Dec 13, 2012 at 10:31 AM
Edited Dec 14, 2012 at 9:22 AM
|
Dear Friends,
There's a potential feature that is missing in LINQ to Entities that I would like to discuss here i.e. being able to resolve and materialize queries with client-side expressions in their final projection (select) part. For example a query like:
var query = from a in myModel.Foo
select new {
Output = string.Format(a.FormatString, a.Parameter1, a.Parameter2, a.Parameter3),
};
Currently causes LINQ to Entities provider to throw an exception indicating that string.Format is not a recognized method for LINQ to Entities. What I expect from LINQ to Entities is fetching the inputs for evaluating the client-side expressions like string.Format
and evaluate these expressions during the materialization process.
I understand that queries like what I've presented cannot be further composed with LINQ operators anymore and allowing the programmer to write such queries might require a considerable insight/awareness from the programmer to distinguish which parts of his/her
query is evaluated server-side (i.e. SQL Server or other DBMS) and which part is evaluated client-side (the application executing the query) but I still find it useful preventing use of more complex and unreadable notions such as:
var query = (from a in myModel.Foo select new {
a.FormatString,
a.Parameter1,
a.Parameter2
})
.ToList()
.Select(a => new {
Output = string.Format(a.FormatString, a.Parameter1, a.Parameter2, a.Parameter3),
});
BTW, the very same feature is available in LINQ to SQL and as an experienced user of LINQ to SQL I have wrote a dozen of apps in production that are heavily utilizing it. And Lack of this feature is the only thing that makes it hard for me to migrate my
existing code to EF.
I would like to know the opinion of EF team/community about this feature and if you also find it useful, I would like to implement and submit it as a contribution to EF base.
|