views:

70

answers:

2

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();
    }
+1  A: 

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

SLaks
+1: I think this is a sensible suggestion. Why did it get a downvote?
Mark Byers
Why was this downvoted?
SLaks
@Slaks +1 for this suggestion..
Pandiya Chendur
@Slaks look at my edited portion...
Pandiya Chendur
If there are no results, it will return `null`.
SLaks
@slaks `RegistrationBO` or `IQueryable<RegistrationBO>` what is the difference between the two? What should i use?
Pandiya Chendur
+3  A: 

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);
Mark Byers
@Mark look at my edited portion...
Pandiya Chendur
@Pandiya Chendur: If there are no matching rows then FirstOrDefault returns `null`.
Mark Byers
@Mark should i use `RegistrationBO` or `IQueryable<RegistrationBO>`... Whats the difference between the two?
Pandiya Chendur
@Pandiya: The main difference is that the first returns only a single object, the second can return many objects.
Mark Byers
@Mark well said... Thanks Mark..
Pandiya Chendur