实体框架(3.5):如何将某个 LINQ 查询转换为 eSQL?
我有以下 LINQ 查询,需要将其转换为 Entity SQL /eSQL):
return (ObjectQuery<User>) from user in Users
where !user.Roles.Any(r => r.AnIntegerProperty < 0)
select user;
User.Roles 是与 Roles 的 n:m 关系的导航属性,反之亦然还有一个 Role.Users 导航属性。模型中没有可用的 User_Roles 或 Roles_User 实体,我无法添加它们。
我也不能在这里使用 LINQ 语句,因为我需要添加 .OrderBy("it." + propertyname) (来自另一个源,也无法更改它),如果构建了 ObjectQuery,这是不可能的与 linq 。
那么如何将其转换为 eSQL 呢?我在哪里可以找到好的 eSQL 示例?到目前为止,我搜索了一整天,必须承认 eSQL 参考很糟糕,并且网络上没有任何可用的示例。
I have the following LINQ query that I need to translate to Entity SQL /eSQL):
return (ObjectQuery<User>) from user in Users
where !user.Roles.Any(r => r.AnIntegerProperty < 0)
select user;
User.Roles is an navigation property to the n:m relation to Roles and there also is a Role.Users navigation property the other way round. There aren't User_Roles or Roles_User Entities available in the model, and I can't add these.
I also can't use the LINQ statement here, because I need to add .OrderBy("it." + propertyname) (comes from another source, can't change that too) later on which is not possible if the ObjectQuery is build with linq.
So how do I translate this to eSQL? And where can I find good eSQL samples? I searched for a whole day until now and must admit that eSQL reference is lousy and there aren't any usable examples around the web.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您还没有找到解决方案,这将起作用
In case you haven't find solution, this will work
我认为动态 linq 库可能是这里的解决方案:
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic -query-library.aspx
您可以使用动态属性名称创建过滤表达式,因此无需进行翻译。
I think that dynamic linq library may be solution here:
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
You can create filtering expressions using dynamic property names, so there is no need to make translations.
我会写一些类似
未测试的东西,但我已经尝试过类似的东西,所以这应该适合你。
I'd write it something like
not tested but I've already tried something similar so thi should work for you.
如果不了解用户和角色可用的具体信息,就很难找到答案。但是,鉴于您所说的,以下内容会起作用:
It is difficult to find an answer without knowing the specifics of what is available on Users and Roles. However, given what you have said, will the following work: