ObjectContext.GetObjectType(e.GetType()) not returning the entity type of the POCO entity(ObjectContext.GetObjectType(e.GetType()) 不返回 POCO 实体的实体类型)
问题描述
ObjectContext.GetObjectType 方法应该返回与指定类型的代理对象关联的POCO实体的实体类型"
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?
我正在使用实体框架 6 候选版本
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";
推荐答案
你使用了错误的 ObjectContext
.EF6 不是基于 System.Data.Entity.dll 构建的.您需要使用 EntityFramework.dll 中的 ObjectContext
.如果您使用 EF6 来避免这种情况,实际上不建议在您的项目中引用 System.Data.Entity.dll.
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.
解决您的问题:
- 删除对 System.Data.Entity.dll 的引用(以防万一)
- 将
System.Data.Objects.ObjectContext.GetObjectType(e.GetType());
替换为System.Data.Entity.Core.Objects.ObjectContext.GetObjectType(e.GetType())
这篇关于ObjectContext.GetObjectType(e.GetType()) 不返回 POCO 实体的实体类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ObjectContext.GetObjectType(e.GetType()) 不返回 POCO 实体的实体类型


基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01