ExpressionExtensionSQL icon indicating copy to clipboard operation
ExpressionExtensionSQL copied to clipboard

Wrong EntityName in Generated SQL when an Expression is using a member defined in ancestor of the entity.

Open bgiavottoatwork opened this issue 3 years ago • 0 comments

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.

bgiavottoatwork avatar Apr 06 '22 14:04 bgiavottoatwork