gambarra / expressionextensionsql Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://www.nuget.org/packages/ExpressionExtensionSQL/
License: MIT License
Home Page: https://www.nuget.org/packages/ExpressionExtensionSQL/
License: MIT License
Not sure if you are familiar with the PredicateBuilder but it is quite popular and allows easy building on the fly. I've been using this particular version of it because it does not rely Linq-to-Sql InvocationExpressions (which definitely won't work with this extension you've built). So for example it allows us to build it with multiple ANDs and ORs in the WHERE clause like this:
var inner = PredicateBuilder.False<Product>();
inner = inner.Or(p => p.ProductGroupID == 10);
inner = inner.Or(p => p.ProductGroupID == 11);
var outer = PredicateBuilder.True<Product>();
outer = outer.And(p => p.StatusID == 2);
outer = outer.And(inner);
That first line is causing the issue, it's supposed to be just an entry point for the expression tree to build off of but when the SQL gets generated you wind up with (note: bolded sections):
SELECT * FROM [Product] WHERE ((1 AND ([Product].[StatusID] = ( 2))) AND ((0 OR ([Product].[ProductGroupID] = ( 10))) OR ([Product].[ProductGroupID] = ( 11))))
Looking at the expression being built by the PredicateBuilder you see
(True OrElse (param.ProductGroupID == Convert(10, Nullable
1)))`
So that True OrElse is causing the problem, it probably should get rendered as 1=1 instead of just 1? What do you think?
Let's say one used a BaseEntity like this
public class BaseEntity
{
public string Id {get; set;}
}
and want to generate a SQL Expression for this Entity:
public class Derived: BaseEntity
{
public string AnotherField {get; set;}
}
Let's say we have to expressions:
a) Expression<Func<Derived, bool>> = (p)=>p.AnotherField = "A"
b) Expression<Func<Derived, bool>> = (p)=>p.Id = "A"
the former (A) gives, when traslated to SQL, something like "AnotherField = @p1" which is fine.
the latter (B) gives, when traslated to SQL, something like "[BaseEntity].Id = @p1" which is incorrect. it should be
"[Derived].Id = @p1"
Basically, when the SQL Expression is generated, the entity name should be the most derived class for a member name.
I need to do queries with no filter.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.