0

使用下面的这个方法我怎么能没有错误地写这个

return _session.Query<Data.Model.User>().Select(_userMapper.CreateUser)
          .AsQueryable();

但是写这个

return _session.Query<Data.Model.User>().Where(x => x.Username == username)
         .First(_userMapper.CreateUser);

产生错误。

public User CreateUser(Data.Model.User modelUser)
{
    return new User{UserId = modelUser.UserId, Username = modelUser.Username,
                    Email = modelUser.Email, Firstname = modelUser.Firstname,
                    Lastname = modelUser.lastname};
}

无论是返回集合还是单个项目,我都希望它通过 create user 方法进行转换。

4

2 回答 2

1

您需要先Select致电First()

return _session.Query<Data.Model.User>()
               .Where(x => x.Username == username)
               .Select(_userMapper.CreateUser)
               .First();

或者:

return _session.Query<Data.Model.User>()
               .Select(_userMapper.CreateUser)
               .First(x => x.Username == username);
于 2013-08-20T10:58:42.363 回答
1
return _userMapper.CreateUser(_session.Query<Data.Model.User>().First(x => x.Username == username));
于 2013-08-20T10:59:57.557 回答