I\'m new to EF and I\'m trying to use an extension method which converts from my Database type User to my info class UserInfo.
I\'m using data
Change this:
using (var dataContext = new dataContext())
{
users = dataContext.Users.Where(x => x.AccountID == accountId && x.IsAdmin == false);
if(users.Any())
{
ret = users.Select(x => x.ToInfo()).ToList();
}
}
to this:
using (var dataContext = new dataContext())
{
return = dataContext.Users.Where(x => x.AccountID == accountId && x.IsAdmin == false).Select(x => x.ToInfo()).ToList();
}
The gist is that you only want to force the enumeration of the context dataset once. Let the caller deal with empty set scenario, as they should.