Lets say I've got the following entities
User
- UserID
- UserName
- UserNameAsLower
- Profile (Navigation property)
Profile
- UserID
- EmailAsLower
- Language
and I want to return a consolidated object, lets call it a UserDTO, but remove some of the fi开发者_JAVA百科elds that we don't want the user to see (AsLower stuff)
- UserDTO
- UserID
- UserName
- Language
if I write a LINQ query as follows and then apply filtering criteria on it, will it execute at that point since the filter criteria is being applied to the projected class property names?
public IQueryable<UserDTO> GetUsers()
{
IQueryable<UserDTO> users = (from u in Entities.Users select new UserDTO() { UserID = u.UserID, UserName = u.UserName, Email = u.Profile.Email, Language = u.Profile.Email });
users = users.Where( u => u.UserName.Contains("Admin") );
return users;
}
The reason I'm asking is if the database table behind it happens to be really large (millions of records), I want to make sure it doesn't try to load it into memory first.
RIA will execute the LINQ query with all applied filters and only serialize back the results.
Order of operations is this: client constructs IQueryable, client enumerates IQueryable, RIA turns IQueryable.Expression into GET request, server parses GET request into Expression tree and reconstructs IQueryable, server executes expression using IQueryProvider, server serializes response to client.
精彩评论