NHibernate equivalent of LinqToEntitiesDomainService in RIA
When using Entity Framework with RIA domain services, domain services are inherited from LinqToEntitiesDomainService
, which, I suppose, allows you to make LINQ queries on a low level (client-side) which propagate into ORM; meaning that all queries are performed on the database and only relevant results are retrieved to the server and thus the client.
Example:
var query = context.GetCustomersQuery().Where(x => x.Age > 50);
Right now we have a domain service which inherits from DomainService, and retrieves data through NHibernate session as in:
virtual public IQueryable<Customer> GetCustomers()
{
return sessionManager.Session.Linq<Customer>();
}
The problem with this approach is that it's impossible to make specific queries without retrieving entire tables to the server (or client) and filtering them there.
Is there a way to make LINQ querying work with NHibernate over RIA like it works with EF? If not, we're willing to switch to EF because of this, because performance impact would be just too severe.
Thanks.开发者_如何转开发
Have you watched SQL profiler and looked at what is getting queried? When you utilize LINQ, the query is built here in this method, but the actual execution doesn't happen until it is needed.
Because the LINQ provider translates the IQuerable LINQ expression tree into criterion, this works well. If you actually do a filter using LINQ on the client, or the equivalent using the Silverlight Data Source, only the requested records are returned. The query does translate to an appropriate WHERE clause on the database server.
In other words, you are not retrieving all records and then filtering on the server with the code example there. The filter on the client gets translated all the way through to the database server and the filter occurs there.
精彩评论