EF object without public key

I want to create an object in EF without a public key. The back table has a unique key, but the data in the table conceptually does not have a unique primary key that it can use.

Looks like EF really doesn't like it. Is there a way to make EF recognize that the table does not have a primary key and still works with it, without any performance improvement? I don't care if the result is read-only.

+3
source share
2 answers

As I understand it, since the Entity Framework is based on the Entred Driven Design concept for Entities, each Entity should by definition have a unique identifier. If the concept that the data in your table represents does not conceptually have a unique identifier, then this is not an entity, in the sense that the framework provides.

With that in mind, I would define a stored procedure by making it accessible through my object context , and then make the objects encapsulating this data through a class that lazily loads the data, manually map it to the objects you use, and present them read-only .

+2
source

You can also do this by exposing the view and then matching your entity with the view.

0

All Articles