Incorrect translation of comparison of current value with owned type default value #30996
Description
We have:
- EF EntityFrameworkCore (7.0.5)
- Database provider: Microsoft.EntityFrameworkCore.SqlServer
- Target framework: .NET 7.0
- Automapper last version (12.0.1)
Test case:
Entity with Owned property. Map to DTO via "ProjectTo".
The main problem is that the mapping works only in the situation when all the properties are filled in, otherwise the owned property is not mapped. In my opinion, it happens due to the fact that the expression translation
(where the comparison with the empty model is done) checks if all properties of the owned model are filled in instead of checking the filling in of one property, at least.
My example: https://github.com/d-kistanov-parc/EF_Automapper_Error_OwnType/blob/master/ConsoleApp/Program.cs
In other words, when i use ProjectTo method, the following Expression is formed:
db.Requests.ProjectTo<RequestDto>(config).Expression
{
[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression]
.Select(dtoRequest => new RequestDto()
{
Id = dtoRequest.Id,
Info = IIF((dtoRequest.Info == default(Object)), null, new RequestInfoDto()
{
Text = dtoRequest.Info.Text,
Number = dtoRequest.Info.Number
})
})
} System.Linq.Expressions.Expression {System.Linq.Expressions.MethodCallExpression2}
EntityFramework translates it into:
SELECT
[r].[Id],
CASE
WHEN([r].[Info_Number] IS NULL) OR ([r].[Info_Text] IS NULL) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END,
[r].[Info_Text],
[r].[Info_Number]
FROM[Requests] AS[r]
I have got a question. Why is there "OR" operator, not "AND" ?
Activity