开发者

[Linq-To-Sql]How to return two values of different datatypes?

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


You need to define a class to contain the result then use this:

return (from r in taxidb.Registrations
       where (r.EmailId == emailId && r.Password == password)
       select new SomeClass { r.UserId, r.UserName });

Seems pointless though... SLaks is right that you can just return the user:

return (from r in taxidb.Registrations
       where (r.EmailId == emailId && r.Password == password)
       select r);


You should return the entire User objects, by change the select clause to select r and changing the return type to IQueryable<User>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜