Hi, I'am really confused about this issue that I've been facing using the deferred loading features of entity framework.
I know the extensions that trigger the database query like .ToList(), .Count(), etc.
My question is, if you are using IEnumerable DTO as return type, will this trigger the database query?
Example you have the following DTO:
public DtoUser
{
public string Name { get; set; }
public int Age { get; set; }
}
And you have this method on your business layer:
public BLLUser
{
public IEnumerable<User> GetAllUser
{
var output = from u in context.User
select new DtoUser
{
Name = u.Name,
Age = u.Age
};
}
}
And I will call it as:
private void GetUserOnBll()
{
using (BLLUser b = new BLLUser())
{
var dtoUser = b.GetAllUser();
// can I still do this without triggering the database query
// or the query is already been triggered
// since the return type is an IEnumerable DTO
var filtered = dtoUser.Where(n => n.Name == "TEST");
}
}
will the "b.GetUser()" method will trigger the database query or do I have to use the .ToList() for it to trigger the query?
No comments:
Post a Comment