内部加入LINQ

时间:2018-02-21 16:39:07

标签: c# sql database linq

我是Linq的新手。对于学习视角,我试图将以下sql查询转换为linq查询。但是,这没有给我什么。没有错误消息或任何东西。 sql查询给了我表,但linq没有给我值。 SQL查询:

SELECT        
Members.FirstName, 
Members.LastName, 
PhoneScreens.BaselineEligibility
FROM            
Members INNER JOIN PhoneScreens ON Members.Id = PhoneScreens.MemberId
WHERE PhoneScreens.BaselineEligibility = 'eligible'

Linq查询是:

context.Members
            .Include(p => p.PhoneScreens)
            .Where(y => y.PhoneScreens.BaselineEligibility == "eligible")
            .ToListAsync();

编辑: 以下是课程:

public class Member
{
   public string FirstName { get; set; }
   public string LastName { get; set; }

   public ICollection<PhoneScreen> PhoneScreens { get; set; }

   public Member()
   {
       PhoneScreens = new Collection<PhoneScreen>();
   }

}

public class PhoneScreen
{
    public string BaselineEligibility { get; set; }

    public Member Member { get; set; }
    public int MemberId { get; set; }
}

我将不胜感激。

1 个答案:

答案 0 :(得分:0)

这将完成工作:

context.Members
            .Include(c => c.PhoneScreens)
            .Where(m => m.PhoneScreens.Any(i => i.BaselineEligibility == "eligible"))