You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class Document
{
public long Id;
public DocumentCategory? Category;
}
public class DocumentCategory
{
public long Id;
public string Name;
}
I would like to do this query:
private Expression<Func<Document, Document>> GetProjeciton()
{
return x => new Document
{
Id = x.Id,
Category = new DocumentCategory()
{
Id = x.Category.Id,
Name = x.Category.Name,
}
};
}
return await _context.Documents
.AsNoTracking()
.Select(GetProjeciton())
.Where(x => x.Id == 1)
.ToListAsync();
But I get an exception: "Nullable object must have a value."
I have check the T-SQL the database receives, and it is correct, it is left join, but it seems that when EF Core tries to create the objects, it fails.
I have another properties that can't be null so the databse always return a value and it works as expected.
How could set the category in the projection?
Thanks.
The text was updated successfully, but these errors were encountered:
Hello:
I am using Entity Core 7.
I have this model:
I would like to do this query:
But I get an exception: "Nullable object must have a value."
I have check the T-SQL the database receives, and it is correct, it is left join, but it seems that when EF Core tries to create the objects, it fails.
I have another properties that can't be null so the databse always return a value and it works as expected.
How could set the category in the projection?
Thanks.
The text was updated successfully, but these errors were encountered: