LINQ留下过滤加盟加盟
问题描述:
我得到重复,这里饭菜LINQ留下过滤加盟加盟
IEnumerable<DTOHotMealsPrice> lst = (from m in this.dbEntity.HOT_MEALS
join ml in this.dbEntity.HOT_MEALS_PRICE on m.MEALSID equals ml.MEALSID into mls
from mls1 in mls.DefaultIfEmpty()
where mls1.HOTID==hotelId
select new DTOHotMealsPrice
{
MEALSID = m.MEALSID,
MEALSNAME = m.MEALSNAME,
CHPRICE = mls1.CHPRICE,
PRICE = mls1.PRICE,
HOTID = mls1.HOTID
}).Distinct().ToList();
我想列出所有HOT_MEALS并与 HOT_MEALS_PRICE加入时,就可以了mealsid参考
当mls1.HOTID==hotelId
,这将越来越innerjoin结果 怎么可能将一个正确的结果
答
双向解决方案
删除哪里案例
加入其中案例在加入表
显示在哪里案例吹LINQ查询
第一查询
IEnumerable<DTOHotMealsPrice> lst = (from m in this.dbEntity.HOT_MEALS
join ml in this.dbEntity.HOT_MEALS_PRICE.where(c=>c.HOTID==hotelId) on m.MEALSID equals ml.MEALSID into mls
from mls1 in mls.DefaultIfEmpty()
select new DTOHotMealsPrice
{
MEALSID = m.MEALSID,
MEALSNAME = m.MEALSNAME,
CHPRICE = mls1.CHPRICE,
PRICE = mls1.PRICE,
HOTID = mls1.HOTID
}).Distinct().ToList();
二是:
IEnumerable<DTOHotMealsPrice> lst = (from m in this.dbEntity.HOT_MEALS
join ml in this.dbEntity.HOT_MEALS_PRICE on m.MEALSID equals ml.MEALSID into mls
from mls1 in mls.where(c=>c.HOTID==hotelId).DefaultIfEmpty()
select new DTOHotMealsPrice
{
MEALSID = m.MEALSID,
MEALSNAME = m.MEALSNAME,
CHPRICE = mls1.CHPRICE,
PRICE = mls1.PRICE,
HOTID = mls1.HOTID
}).Distinct().ToList();
请提供你的表结构。 –
'public partial class HOT_MEALS { public short MEALSID {get;组; } public string MEALSNAME {get;组; } } public partial class HOT_MEALS_PRICE { public short MEALSID {get;组; } public int HOTID {get;组; } public Nullable PRICE {get;组; } public Nullable CHPRICE {get;组; ' }' –