如何在构建时为 LINQ-to-Entity 标记任何不受支持的 LINQ 运算符
今天,一位团队成员签入了一些看起来像这样的代码
var query = repository.GetQueryable<Customer>()
.OrderBy(c => c.Name)
.Select( (c, i) => new{Order = i, Customer = c});
显然,这个查询不适用于实体框架,因为 Select 方法的特定重载是 不受支持。 问题是,直到运行时您才会知道不受支持的方法的任何可能用法。
有没有办法在构建期间获得某种反馈?我正在考虑编写一个自定义 FxCop 规则,但我想在 Stackoverflow 上提出这个问题,以防有人有更好的想法。
Today, a fellow team member checked-in some code that looked like this
var query = repository.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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否有针对实际数据库运行 LINQ 查询的集成测试?
这就是我要开始努力的地方——这样你就可以测试整个查询;不仅支持查询运算符的哪些重载,还支持各个子句的内容。
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.