开发者

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?

  1. I revert back the return type to IQueryable<AuthenticateUserResult>
  2. Added SingleOrDefault() as extension.
  3. 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;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜