Hi,
I have a model on top of my database model and map the objects in my Repository.
However, apparently it makes a difference whether I "select new" directly in my GetUsers or "select factoryresult" as implemented below. I get the error at runtime, that the method CreateFromDbModel does not have a translation to sql (System.NotSupportedException).
Is there a way around this? Can I mend it somehow?
The reason for wanting to use the factory method is that I might instanciate objects elsewhere and want to keep the 'mapping code' in one place...
Thanks for any comments, Anders
public IQueryable<User> GetUsers(bool includeTeams)
{
return from u in _db.sc_Players
where (includeTeams || (!u.aspnet_User.sc_Player.IsTeam))
select UserFactory2.CreateFromDbModel(u);
}
public static User CreateFromDbModel(sc_Player player)
{
return new User
{
Id = player.sc_PlayerID,
FirstName = player.FirstName.Trim(),
LastName = player.LastName.Trim(),
PresentationName = player.FirstName.Trim() + " " + player.LastName.Trim(),
LoginName = player.aspnet_User.LoweredUserName,
IsTeam = player.IsTeam,
Email = player.aspnet_User.aspnet_Membership.Email,
Password = player.aspnet_User.aspnet_Membership.Password
};
}