Today, a fellow team member checked-in some code that looked like this
var query = reposi开发者_C百科tory.GetQueryable<Customer>()
.OrderBy(c => c.Name)
.Select( (c, i) => new{Order = i, Customer = c});
Obviously, this query is not going to work against Entity Framework since that particular overload of Select method is unsupported . The problem is that you won't know about any possible usage of unsupported methods until runtime.
Is there a way to get some sort of feedback during build time? I'm thinking about writing a custom FxCop rule but thought ask this question on Stackoverflow in case someone has a better idea.
Do you have integration tests which run your LINQ queries against actual databases?
That's where I'd start to put the effort - that way you'll be testing the whole query; not just which overloads of the query operators are supported, but whether the contents of the various clauses are supported too.
精彩评论