我是LINQ to entity的新手,如何创建动态查询 [英] I am new to LINQ to entity how can I create a dynamic query

查看:116
本文介绍了我是LINQ to entity的新手,如何创建动态查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用LINQ to Entities,我正在尝试创建一个动态查询,它只会动态地选择不同列的部分列和/或顺序。我的背景是编写动态SQL字符串并使用sql客户端类。我更喜欢将LINQ写入实体以进行数据访问,因为它易于编写。有人可以在.NET 4.5.1版和实体版本6中指出正确的方向吗?我很难相信这项伟大的技术无法指定我只想要某些列,而不是为每组列编写不同的方法,或者排序......这使我们想要回到字符串字符串和ADO 。不寻找有人写我的代码只是寻找关于正确的模式的专家建议。谢谢



编辑:我调查了System.Linq.Dynamic,但看起来它在几年内没有更新。我也看了一下ExpressionBuilder类..我意识到有几种方法可以做到这一点,但是不想开始路径并浪费大量时间,因为目前有一种更好的方法。

I have just started using LINQ to Entities and I am trying to create a dynamic query that will only select partial columns and/or order by different columns dynamically. My background was writing dynamic SQL strings and using the sql client classes. I much prefer writing LINQ to Entities for data access because of the ease of writing it.. Can someone please point me in the proper direction in version 4.5.1 of .NET and version 6 of Entity? I have trouble believing that with this great technology there is no way to specify that I only want certain columns with out writing a different method for each set of columns and or ordering... that makes we want to go back to string strings and ADO. Not looking for someone to write my code just looking for expert advice on the proper pattern to pursue. Thank you

I have investigated System.Linq.Dynamic but it looks like it has not been updated in a couple of years. I have also looked at the ExpressionBuilder class.. I realize there are a few ways to do it but don't want to start down a path and waste a bunch of time because there is a better way of doing this currently.

推荐答案

看看这里:

使用LINQ到实体和表达式进行动态查询 [ ^ ]

使用LINQ查询和CrmDataContext的动态实体 [ ^ ]

带有表达式Tre的动态LINQ查询es [ ^ ]

使用表达式树的实体框架中的动态查询 [ ^ ]



我不知道它是否满足您的需求,但它的价值尝试;)
Have a look here:
Dynamic Querying with LINQ-to-Entities and Expressions[^]
Use Dynamic Entity with LINQ Queries and the CrmDataContext[^]
Dynamic LINQ Queries with Expression Trees[^]
Dynamic Queries in Entity Framework using Expression Trees[^]

I have no idea does it meet your needs, but it's worth to try ;)


您可以查看创建您自己的动态LINQ解析器 [ ^ ]。我刚才写了解析器来创建适合LINQ-to-Object查询的谓词。

干杯

Andi
You might check out Invent your own Dynamic LINQ parser[^]. I wrote that parser a while ago to create predicates suitable for LINQ-to-Object queries.
Cheers
Andi


这篇关于我是LINQ to entity的新手,如何创建动态查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆