Entity framework 4 跟踪导航属性中的更改
如何使上下文检测导航属性中的更改。在代码中,我正在删除healthcareCode条目。这是ClaimInformation类中的列表,是虚拟的。1米 this.claiminformation.claiminfo_healthcarecodes[i].remove();这一行连接到上下文Entity framework 4 跟踪导航属性中的更改,entity-framework-4,Entity Framework 4,如何使上下文检测导航属性中的更改。在代码中,我正在删除healthcareCode条目。这是ClaimInformation类中的列表,是虚拟的。1米 this.claiminformation.claiminfo_healthcarecodes[i].remove();这一行连接到上下文 _context.ClaimInformations.Include(h => h.ClaimInformation_HealthCareCode) 此代码将更改的条目返回为“ClaimInform
_context.ClaimInformations.Include(h => h.ClaimInformation_HealthCareCode)
此代码将更改的条目返回为“ClaimInformation”,这部分是正确的,但它必须深入到包含已删除条目的导航属性 私有字符串GetTableName(DbEntityEntry) { ObjectContext=((IOObjectContextAdapter)this.context).ObjectContext; System.Type entityType=ent.Entity.GetType() 将其更改为获取实体名称而不是表名称
_context.ClaimInformations.Include(h => h.ClaimInformation_HealthCareCode)
private string GetTableName(DbEntityEntry dbEntry)
{
string entryName = dbEntry.Entity.GetType().Name;
int length = entryName.IndexOf('_');
TableAttribute tableAttr = dbEntry.Entity.GetType().GetCustomAttributes(typeof(TableAttribute),
false).SingleOrDefault() as TableAttribute;
string tableName = tableAttr != null ? tableAttr.Name : entryName.Substring(0,length);
return tableName;
}
if (entityType.BaseType != null && entityType.Namespace == "System.Data.Entity.DynamicProxies")
entityType = entityType.BaseType;
string entityTypeName = entityType.Name;
EntityContainer container =
objectContext.MetadataWorkspace.GetEntityContainer(objectContext.DefaultContainerName, DataSpace.CSpace);
string entitySetName = (from meta in container.BaseEntitySets
where meta.ElementType.Name == entityTypeName
select meta.Name).First();
return entitySetName;
}