首页 新闻 会员 周边

表关联Linq的Where子句

0
[已解决问题] 解决于 2015-04-22 21:12

各位老师好:

   描述下问题:

 1.

  产品表:

  • id       Model
  • 28 Cosy_Nest 佳宝巢
  • 29  Protect 家适宝
  • 30  MaxiPro 沉思者

 

 --

配置表:

  • id    ProductId   SuitableId
  • 1467   28             1
  • 1468   28             4
  • 1469   28             6
  • 1450   29             2
  • 1451   30             4

--

 2.Sql 语句如下:(已实现)

筛选出产品表中的产品不在 配置表中的条件:结果 product.id as pid=28

 

select product.id as pid,ps.suitableid,* from dbo.Product product --产品表
inner join ProductSuitable ps  --配置表
on ps.ProductId =product.id
where product.id not in  --产品不属于配置表主键 (1,2)的条件
(select productid from ProductSuitable where suitableid in (1,2) )

 

3.期望改写的Linq表达式

IList<Product> list = productComponent.GetProList();/*获得list*/

 list = list.Where(t=>t.productSuitables.Count(x=>x.id < 3) == 0).ToList();

/*想获取配置表中SuitableId不含1,2

目前获得ProductId  28、29、 30 */

4.希望大家给些思路

5.积分有些少,谢谢大家了。

Frank铭的主页 Frank铭 | 初学一级 | 园豆:8
提问于:2014-03-26 20:01
< >
分享
最佳答案
1

不属于1,2 不该是x.id>3吗?

t.productSuitables.Count(x=>x.id < 3) == 0什么意思

奖励园豆:5
xiecm_cnblog | 菜鸟二级 |园豆:207 | 2015-03-16 18:08

谢谢您的回复,这个问题出现时,思路不太清晰,没有描述很清楚。

有Linq 的问题,再请教您吧:)

Frank铭 | 园豆:8 (初学一级) | 2015-04-22 21:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册