Unable to retrieve values using Lambda Expression
My problem is that i want to take entities value of a Linq Resultant. Below is my method
My Datalayer Method:
private static readonly Func<DataContext, String, String, IQueryable<AuthenticateUserResult> > AuthenticateUser__impl= CompiledQuery.Compile((DataContext context, String username, String password) =>
( from u in context.GetTable<Yantriki.MeriRanchi.Web.UI.Core.User>()
where ((u.UserName == username)
&& (u.Password == password)
&& (u.IsActive == true))
select开发者_JS百科 new AuthenticateUserResult
{
MemberId = u.MemberId,
Email = u.Email,
Name = u.Name,
Role = u.Role,
UserName = u.UserName
}));
Above code is generated by Visual Linq Designer. Now I am returning the result to UI layer using the method below:
public static IQueryable AuthenticateUser(User user)
{
var db = new MeriRanchiDataContext();
return MeriRanchiQueries.AuthenticateUser(db, user.UserName, user.Password);
}
At my UI layer I need values stored in the entities, MemberId, Email, Name so that I can set it to session. SO what will be expression for that.
Return the generic IQueryable<AuthenticateUserResult>
instead of the non-generic IQueryable
.
Hi I am answering my own question as I got its solution and thinking it might help other facing the same issue.
What i did?
- I revert back the return type to
IQueryable<AuthenticateUserResult>
- Added SingleOrDefault() as extension.
- Used the code below
var userResults =
MeriRanchiDataManager.AuthenticateUser(user).SingleOrDefault();
Session["UserName"] =userResults.MemberId;
Session["Email"] = userResults.Email;
Session["Role"] = userResults.Role.ToString();
Session["MemberId"] = userResults.MemberId.ToString();
Session["Name"] = userResults.Name;
精彩评论