[Linq-To-Sql]如何返回两个不同数据类型的值?
这是我的存储库方法,它返回 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();
}
Here is my repository method which returns 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);
}
How to return UserName
which is a string along with UserId
... Any suggestion?
EDIT:
I tried this it is working but how to get whether the query result contains records or not,
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要定义一个类来包含结果,然后使用它:
虽然看起来毫无意义... SLaks 是正确的,您可以只返回用户:
You need to define a class to contain the result then use this:
Seems pointless though... SLaks is right that you can just return the user:
您应该返回整个 User 对象,方法是将
select
子句更改为select r
并将返回类型更改为IQueryable
。You should return the entire User objects, by change the
select
clause toselect r
and changing the return type toIQueryable<User>
.