日期:2014-05-20 浏览次数:21068 次
var products= (from p in context.Product join pl in context.ProductLabel on p.ProductId equals pl.ProductId into go from g in go where p.ProductName.Contains(data)||g.Label.Contains(data) select g.Product).Distinct();
create table product (product_id varchar(10),product_name varchar(20)) insert into product values('001','纯银手镯') insert into product values('002','名族手镯') insert into product values('003','印巴风情手镯') insert into product values('004','泰国手镯') insert into product values('005','波西米亚手镯') insert into product values('006','彩绘手镯') create table product_lable (product_id varchar(10),product_lable varchar(20)) insert into product_lable values('001','年轻') insert into product_lable values('001','时尚') insert into product_lable values('003','个性') insert into product_lable values('004','时尚') insert into product_lable values('004','年轻') insert into product_lable values('004','活力') go drop table product drop table product_lable
var products= (from p in context.Product join pl in context.Product_lable.Where(l=>l.Content.Contains(data)) on p.Product_id equals pl.Product_id into go from pl in go.DefaultIfEmpty() where p.Product_name.Contains(data) select new { p.Product_id, product_name =p.Product_name, lable=pl==null?"":pl.Content }).Distinct();
------解决方案--------------------
var products= (from p in context.Product join pl in context.ProductLabel on p.ProductId equals pl.ProductId into go from g in go.DefaultIfEmpty() where p.ProductName.Contains(data)||g.Label.Contains(data) select g.Product).Distinct();
------解决方案--------------------
上面的大小寫有誤,另外Content其實是product_lable這個欄位。