ObjectContext.GetObjectType(e.GetType())不返回POCO实体的实体类型 [英] ObjectContext.GetObjectType(e.GetType()) not returning the entity type of the POCO entity

查看:109
本文介绍了ObjectContext.GetObjectType(e.GetType())不返回POCO实体的实体类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的的 ObjectContext.GetObjectType方法应该返回与指定类型的代理对象关联的POCO实体的实体类型为



那么,如何来在我的代码它只是返回的代理?



我使用实体框架6候选发布版

  //软删除
变种E = Context.Set< T>()找到(ID);
e.IsDeleted = TRUE;
InsertOrUpdate(E);

型T = System.Data.Objects.ObjectContext.GetObjectType(e.GetType());
字符串名称= t.Name;
// Property_6C887DE7274181E6E99D6FCF2C21BDD59E226F99B0064F59954E70062C135331

//当然,我不应该在这里使用子串?
NAME = name.Substring(0,name.IndexOf(_))ToSpacedTitleCase()。
字符串消息=名+删除;


解决方案

您使用了错误的 ObjectContext的。 EF6不是建立在System.Data.Entity.dll。您需要使用的ObjectContext 从EntityFramework.dll。它实际上是不建议让所有,如果您使用EF6避免像这种情况在项目中System.Data.Entity.dll参考。



要解决您的问题:




  • 删除提及System.Data.Entity.dll(以防万一)

  • 更换 System.Data.Objects.ObjectContext.GetObjectType(e.GetType()); System.Data.Entity.Core.Objects.ObjectContext .GetObjectType(e.GetType())


The ObjectContext.GetObjectType Method should return "the entity type of the POCO entity associated with a proxy object of a specified type"

So how come in my code it just returns the proxy?

I am using entity framework 6 release candidate

        //Soft delete
        var e = Context.Set<T>().Find(id);
        e.IsDeleted = true;
        InsertOrUpdate(e);

        Type t = System.Data.Objects.ObjectContext.GetObjectType(e.GetType());
        string name = t.Name;
        //Property_6C887DE7274181E6E99D6FCF2C21BDD59E226F99B0064F59954E70062C135331

        //Surely I shouldn't have to use Substring here?
        name = name.Substring(0, name.IndexOf("_")).ToSpacedTitleCase();
        string message = name + " deleted";

解决方案

You are using the wrong ObjectContext. EF6 is not built on System.Data.Entity.dll. You need to use ObjectContext from EntityFramework.dll. It's actually not recommended to have a reference to System.Data.Entity.dll in your project at all if you are using EF6 to avoid situation like this.

To fix your issue:

  • remove the reference to System.Data.Entity.dll (just in case)
  • replace System.Data.Objects.ObjectContext.GetObjectType(e.GetType()); with System.Data.Entity.Core.Objects.ObjectContext.GetObjectType(e.GetType())

这篇关于ObjectContext.GetObjectType(e.GetType())不返回POCO实体的实体类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆