linq在join中将join连接过滤

时间:2017-05-26 08:27:36

标签: c# linq entity-framework-6

我在这里吃重复的饭菜

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当一个用餐参考上面

mls1.HOTID==hotelId时,这将获得内部结果 怎么会有一个合适的结果

1 个答案:

答案 0 :(得分:0)

双向解决方案

删除Where Case

添加案例加入表格

显示Where Case Blow Linq查询

首先查询

minLargerDimention

第二是:

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();