Get underlying entity object from entity framework proxy

前端 未结 6 1767
逝去的感伤
逝去的感伤 2020-12-04 16:41

I have an entity by getting it from DbEntityEntry.Entity. This returns the Entity Framework proxy for the entity.

How do I access the underlying object

6条回答
  •  我在风中等你
    2020-12-04 17:13

    While working with EF 6 i used the following code to get the underlying POCO entity type from proxy type,

    var entityType = ObjectContext.GetObjectType(dbEntitymodifiedEntry.Entity.GetType());
    

    ObjectContext.GetObjectType : Return the POCO from proxy object

    reference : https://docs.microsoft.com/en-us/ef/ef6/fundamentals/proxies

提交回复
热议问题