简体   繁体   English

System.Linq.Dynamic,EntitySQL和表达式树之间的差异

[英]Differences between System.Linq.Dynamic, EntitySQL and Expression Trees

I am currently working on a large project that uses Entity Framework extensively. 我目前正在开发一个广泛使用Entity Framework的大型项目。 Part of the functionality we have implemented is dynamic querying (Filter/Sort) of the various data models based on user-supplied filters. 我们实现的部分功能是基于用户提供的过滤器对各种数据模型进行动态查询(过滤/排序)。

To achieve this I ended up using System.Linq.Dynamic which allows me, through various means, to create string-based filters like like "SomeProperty.StartsWith(@P0)" and so on, and then pass these strings (and attendant parameters) to the Dynamic Linq extension methods for IQueryable<T> ( Where , etc) so that they get executed against the database and everyone is happy. 为了实现这一点,我最终使用了System.Linq.Dynamic ,它允许我通过各种方式创建类似"SomeProperty.StartsWith(@P0)"类的基于字符串的过滤器,然后传递这些字符串(和话务员参数) )为IQueryable<T>Where等)的Dynamic Linq扩展方法,以便它们对数据库执行,每个人都很高兴。

I didn't know any other way to do this at the time except for a vague notion of Expression Trees and to be honest, I just could not get my head around them - I spent several weeks poring over a decompilation of a component that used expressions to implement dynamic querying and I balked :) 当时除了表达树的模糊概念之外,我还不知道有什么其他方法可以做到这一点,说实话,我无法理解他们 - 我花了几个星期的时间仔细阅读使用过的组件的反编译用于实现动态查询的表达式,我犹豫不决:)

Plus it felt like I was reinventing the wheel when the functionality I needed effectively was already written by far cleverer people than myself, in the System.Linq.Dynamic extensions. 另外,当我需要有效的功能已经由远比我自己更聪明的人在System.Linq.Dynamic扩展中编写时,感觉我正在重新发明轮子。

Now the current code all works quite well as a generalised solution for filtering, sorting, etc, on any of my entities, and I'm happy enough with it however as I became more and more familiar with EF I started to come across things like 现在,当前的代码都可以很好地作为我的任何实体上的过滤,排序等的通用解决方案,我很高兴它随着我越来越熟悉EF我开始遇到像

And I started to wonder, given that System.Linq.Dynamic is nearly 6 years old, and hasn't really had anything done with it in that time, am I missing out on anything? 我开始怀疑,鉴于System.Linq.Dynamic已经将近6年了,并且在那段时间里没有真正做过任何事情, 我错过了什么吗? or, have I missed some fundamental point? 或者, 我错过了一些基本点吗?

  • Should I bite the bullet and move my codebase over to use EntitySQL ? 我应该咬紧牙关并移动我的代码库来使用EntitySQL吗? (I assume this is like the spiritual successor to System.Linq.Dynamic , or am I wrong?) (我认为这就像System.Linq.Dynamic的精神继承者,或者我错了?)

  • Or should I go back and learn how to use Expression Trees because they are the way of the future/all the cool kids do it, etc? 或者我应该回去学习如何使用Expression Trees因为它们是未来的方式/所有酷孩子都这样做,等等? I'm not a fan of change for changes sake, and I like code that works, but I am worried that at some point in the future string-based dynamic linq becomes a dead-end and I'm stuck using it. 我不喜欢变化的粉丝,我喜欢有效的代码,但是我担心在未来的某些时候基于字符串的动态linq会变成一个死胡同,而我却坚持使用它。

If anyone can help to clarify the differences between System.Linq.Dynamic and EntitySQL , or can identify any good reason for moving to Expression Trees I'd really appreciate it. 如果有人可以帮助澄清System.Linq.DynamicEntitySQL之间的差异,或者可以找出转移到Expression Trees任何好理由,我真的很感激。

We are using Dynamic Linq extensively in our project... Its clean and it works well, but its very complicated if you would want to peep into or change anything its code. 我们在我们的项目中广泛使用Dynamic Linq ...它很干净并且运行良好,但如果您想窥视或更改其代码,它会非常复杂。

One of the problems what I found using a combination of Dynamic Linq and EF 6 is EF 6 uses query caching to perform faster retrieval of data and the way where query that is built in Dynamic Linq does not use this feature of EF 6. So we have to change the where to use query caching. 其中一个我发现使用动态LINQ和EF 6的组合问题是EF 6使用查询缓存来进行更快的数据检索和那里是建立在动态的LINQ查询不使用EF 6.因此,我们的这一功能的方式必须更改使用查询缓存的位置。

This is just a small example to say Dynamic Linq is not meant for newer EF versions. 这只是一个小例子,说动态Linq不适用于较新的EF版本。 Dynamic Linq is a wonderful solution if you want to work with un-typed collection like IQuerable, but its very difficult to maintain. 如果你想使用像IQuerable这样的非类型集合,那么Dynamic Linq是一个很棒的解决方案,但它很难维护。

I am hoping you would work in a typed environment(IQueryable). 我希望你能在一个打字的环境中工作(IQueryable)。 Otherwise essentially you would need to modify Dynamic Linq to really take advantage of EF 6. 否则,您基本上需要修改Dynamic Linq才能真正利用EF 6。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM