DynamicExpressions | dynamic expression builder that can be | Database library
kandi X-RAY | DynamicExpressions Summary
kandi X-RAY | DynamicExpressions Summary
A dynamic expression builder that can be used to dynamically sort and/or filter LINQ/EF queries. I wrote a blog post that explains the usage & benefits, check it out here. This library tries to generate Expression Trees as close to the one generated by c# as possible, so in almost all cases, you don't even need to worry about performance.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of DynamicExpressions
DynamicExpressions Key Features
DynamicExpressions Examples and Code Snippets
Community Discussions
Trending Discussions on DynamicExpressions
QUESTION
I am currently implementing some dynamic filtering/sorting and thought it was a good idea to do a benchmark to see how things are looking.
First, here's the method creating an expression acting as a "getter":
...ANSWER
Answered 2020-May-15 at 23:50The problem is your GetPropertyGetter
method generates a lambda that converts the result of the property into an object
. When OrderBy
sorts by object
instead of by string
, the comparison used is different. If you change the lambda to p => (object)p.Title
you will discover it is faster as well. If you change the OrderByDescending
to take a StringComparer.InvariantCulture
, you will see a slight speed up over your generated lambdas.
Of course, that also means your dynamic OrderBy
most likely doesn't handle other languages properly.
Unfortunately once you start to dynamically create code like the lambda for a LINQ method, you can't always just substitute object
and expect the same results (e.g. an int
field will be boxed, string
won't use the same comparer, types with custom comparers may not work, ...). Basically I think of Expression
building for dynamic type handling as like the GPL - it spreads out (and up) like a virus. If you replaced OrderByDescending(GetPropertyGetter)
with dynamic OrderByPropertyNameDescending(string)
and built the call to OrderBy
as well, you would get what you expect.
Consider:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install DynamicExpressions
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page