开发者

How to flag any unsupported LINQ operator for LINQ-to-Entity at build time

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜