-
Notifications
You must be signed in to change notification settings - Fork 3.3k
A combination of downcast and owned types could not be translated in 3.1, but could in 3.0 #19138
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Note for triage: stack trace:
|
Note for triage: my understanding from triage was that var thisCausesAnErrorIn31ButNot30 =
db
.BaseEntities
.OfType<SubEntity>()
.Select(b =>
db.OtherEntities
.Where(o => o.OtherEntityData == b.Data)
.FirstOrDefault()
);
var errorHappensOnThisLine = thisCausesAnErrorIn31ButNot30.ToArray(); returns different results. Specifically, in will filter out any non-SubEntity instances rather than returning null for them. |
Scratch that! |
Probably combination of other filters/set operations etc can get desired behavior. |
Hi, Thanks for looking into this :-) I have posted the minimum repro for the issue, which could be worked around. As it stands, the code actually looks sloppy. The expression in our code that uncovered the issue contains a ternary expression, which, while not required to reproduce the error, gives some purpose to the structure of the code. db
.BaseEntities
.Select(b =>
b is SubEntity
? db.OtherEntities
.Where(o => o.OtherEntityData == ((SubEntity)b).Data)
.FirstOrDefault()
: ((SubEntity2)b).OtherEntity
);
...
public class OtherSubEntity2 : BaseEntity
{
public OtherEntity OtherEntity { get; set; }
} So a workaround using |
- Skip/Take does not force applying pending selector and changing shape. - Throw translation failure message for Querayble methods which we don't translate (hence we don't process in navigation expansion). Earlier we threw query failed message. Now Navigation Expansion does not throw QueryFailed error message from any place. - Unwrap type conversion for validating member access during include expansion so that we don't generate include when derived type's member is accessed. Resolves #18140 Resolves #18374 Resolves #18672 Resolves #18734 Resolves #19138 Resolves #19207
- Skip/Take does not force applying pending selector and changing shape. - Throw translation failure message for Querayble methods which we don't translate (hence we don't process in navigation expansion). Earlier we threw query failed message. Now Navigation Expansion does not throw QueryFailed error message from any place. - Unwrap type conversion for validating member access during include expansion so that we don't generate include when derived type's member is accessed. Resolves #18140 Resolves #18374 Resolves #18672 Resolves #18734 Resolves #19138 Resolves #19207
- Skip/Take does not force applying pending selector and changing shape. - Throw translation failure message for Querayble methods which we don't translate (hence we don't process in navigation expansion). Earlier we threw query failed message. Now Navigation Expansion does not throw QueryFailed error message from any place. - Unwrap type conversion for validating member access during include expansion so that we don't generate include when derived type's member is accessed. Resolves #18140 Resolves #18374 Resolves #18672 Resolves #18734 Resolves #19138 Resolves #19207
- Skip/Take does not force applying pending selector and changing shape. - Throw translation failure message for Querayble methods which we don't translate (hence we don't process in navigation expansion). Earlier we threw query failed message. Now Navigation Expansion does not throw QueryFailed error message from any place. - Unwrap type conversion for validating member access during include expansion so that we don't generate include when derived type's member is accessed. Resolves #18140 Resolves #18374 Resolves #18672 Resolves #18734 Resolves #19138 Resolves #19207
When running the supplied code in Efcore 3.0.1, it successfully runs to completion. When running it in Efcore 3.1.0-preview3.19554.8, it throws an
InvalidOperationException
with the messageCould not be translated
.Code to reproduce
Code that doesn't produce the error
If the
Owned
property is removed fromSubEntity
, it runs fine.It also works, if the cast is removed, by adding an
OfType
as follows:Full error message
Technical details
EF Core version: Efcore 3.1.0-preview3.19554.8 (but not in 3.0.1)
Target Framework: netcoreapp3.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating System: Windows Server 2016 Datacenter 10.0.14393 Build 14393
IDE: Visual Studio Professional 2019 16.3.4
The text was updated successfully, but these errors were encountered: