I use ASP.MVC / EF in my project.
The domain model as below:
public class Post
{
public int Id {get;set;}
public string Abstract {get;set;}
public string Content {get;set;}
}
and the view model is
public class PostListView
{
public int Id {get;set;}
public string Abstract {get;set;}
}
statemens in action to get model:
db.Posts.Where(...).Select(p=>new PostListView
{
Id = p.Id,
Abstract = p.Abstract
});
When I check the SQL generated by Entity Framwork, the select statement includes all three columns. Is there some way to make EF generate more effective SQL statements that only select the fields needed by view model?
Thank you!
Where?