[Linq-To-Sql] How to return two values ββof different data types?
Here is my repository method that 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 but it works, but how to get the query result whether it 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();
}
+2
a source to share
2 answers
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 simply return the user:
return (from r in taxidb.Registrations
where (r.EmailId == emailId && r.Password == password)
select r);
+3
a source to share