question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow owned entities on a keyless entity type

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
kgaskacommented, Mar 12, 2021

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.

1reaction
smitpatelcommented, Sep 17, 2019

@aherrick - Can you elaborate more exactly what are you trying to achieve? What is the view definition and what part is causing issue?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found