Allow owned entities on a keyless entity type
See original GitHub issueI have a simple view in my DB that is exposing some fields joined from multiple tables.
I’m able to map my view to my object similar to below:
public IQueryable<MyDbView> MyDbView => Query<MyDbView>();
modelBuilder.Query<MyDbView>().ToView(nameof(MyDbView));
MyDbView is an object similar to below.
public class MyDbView
{
public string Name { get; set; }
public Address OriginAddress { get; set; }
public Address DestinationAddress { get; set; }
}
public class Address
{
public int Id { get; set; }
public string Name { get; set; }
public string City { get; set; }
public string State { get; set; }
}
Since the view has flattened the 2 Address fields into 6 fields (OriginAddressName
, OriginAddressCity
, etc.), I’d like to inflate them back to the object so MyDbView
doesn’t have to have a direct mapping to each of the fields and I can reuse my types.
How is the possible?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Keyless Entity Types - EF Core
How to configure keyless entity types using Entity Framework Core.
Read more >The entity type 'Access' requires a primary key to be ...
The entity type 'Access' requires a primary key to be defined. If you intended to use a keyless entity type call 'HasNoKey()' ;...
Read more >How to Define Keyless Entities in .NET EF Core
If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. The error is asking to define a primary key on...
Read more >Using Value Objects with Entity Framework Core
Owned types can reference other entities, either owned (nested owned types) or non-owned (regular reference navigation properties to other ...
Read more >Owned Entity Types - EF Core Advanced Topics
Owned entities do not contain a key or identity property of their own, but would always be a navigational property of another entity....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Is there any reason why keyless entity cannot have owned type which origin is from the exactly same table? It would be very useful to be able simplify/reuse entity model for views or tables without primary key.
@aherrick - Can you elaborate more exactly what are you trying to achieve? What is the view definition and what part is causing issue?