-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error projecting child entity fields to specific class #5883
Comments
This is because the relationship is optional, so if the Interestingly, if this were a LINQ to Objects query, then you'd get a NullReferenceException if You could make the relationship required, if protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Model>()
.HasOne(p => p.Child)
.WithMany()
.IsRequired();
} Or, you can defend against nulls in the query.
|
Thanks. Figures I was doing something silly like that. It's odd that this scenario works for an anonymous type, where the compiler generates a Guid member , but it doesn't work for a defined class with the same member type, or am I missing something here? |
Closing as a duplicate of #5522. We want to change this so that we only throw if an actual null value comes back from the database. |
Steps to reproduce
The issue
When projecting into a specific class, a expression type mismatch occurs.
Additional Information
Projecting to an anonymous type works as expected.
ChildId is of the expected type, Guid.
Projecting to a DTO where ChildId is a Nullable Guid also works.
Further technical details
EF Core version: 1.0.0
Operating system: Windows 10 x64, Version 1511
Visual Studio version: VS Code
EF_Projection.zip
The text was updated successfully, but these errors were encountered: