如果condition为true,则实体框架linq内部连接返回对象

时间:2017-06-30 06:22:30

标签: entity-framework linq entity-framework-6

public UserMaster Login(UserMaster userMaster, string otp)
    {

        return (from um in _context.UserMasters.Where(u => u.UserName == userMaster.UserName && u.Password == userMaster.Password && u.IsDisplay == true && u.IsActive == true)
                join pin in _context.UserPins.Where(p => p.Pin == otp) on um.UserId equals pin.UserId
                select new { um }).SingleOrDefault();
   }

如果条件满足,我试图返回User的对象,即如果用户具有正确的pass和username以及来自不同表的正确otp。我只需要/要求返回用户主对象。

给出以下错误

enter image description here

1 个答案:

答案 0 :(得分:0)

public UserMaster Login(UserMaster userMaster, string otp)
{
       return (from um in _context.UserMasters.Where(u => u.UserName == userMaster.UserName && u.Password == userMaster.Password && u.IsDisplay == true && u.IsActive == true)
              join pin in _context.UserPins.Where(p => p.Pin == otp) on um.UserId equals pin.UserId
              select um).FirstOrDefault();
}