这是我的存储库方法,它返回UserId
,
public IQueryable<int> getLoginStatus(string emailId, string password)
{
return (from r in taxidb.Registrations
where (r.EmailId == emailId && r.Password == password)
select r.UserId);
}
如何返回UserName
这是一个字符串以及UserId
...有什么建议吗?
修改
我试过它它正在工作,但如何查询查询结果是否包含记录,
public RegistrationBO getLoginStatus(string emailId, string password)
{
return (from r in taxidb.Registrations
where (r.EmailId == emailId && r.Password == password)
select new RegistrationBO()
{
UserId = r.UserId,
UserName = r.UserName
}).FirstOrDefault();
}
答案 0 :(得分:3)
您需要定义一个包含结果的类,然后使用它:
return (from r in taxidb.Registrations
where (r.EmailId == emailId && r.Password == password)
select new SomeClass { r.UserId, r.UserName });
看起来毫无意义...... SLaks是对的,你可以退回用户:
return (from r in taxidb.Registrations
where (r.EmailId == emailId && r.Password == password)
select r);
答案 1 :(得分:1)
您应该返回整个用户对象,方法是将select
子句更改为select r
并将返回类型更改为IQueryable<User>
。