using nhibernate as ORM
Trying to get one entity
var users = GetUsersData(repository);
return users.Where(f => f.Id == id).FirstOrDefault();//there is an exception
exception:
Object of type 'System.Linq.EnumerableQuery
1[Entity]' cannot be converted to type 'System.Linq.IQueryable
1[System.Object[]]'.
but when i do it that way:
var users = GetUsersData(repository);
return users.Where(f => f.Id == id).ToArray().FirstOrDefault();
it runs fine. Point me, what's wrong?
in GetUsersData
i do :
private static IQueryable<User> GetUsersData(IUserRepository repository)
{
return repo.GetAll().Select(user => new User
{
Id = user.Id,
Phones = user.Phones.Select(s => new Phone() { Number = s.Number }),
...
}).AsQueryable();