public partial class ClaimEntities : DbContext
{
public ClaimEntities()
: base("name=ClaimEntities")
{
this.Configuration.LazyLoadingEnabled = false;
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<ClaimInformation> ClaimInformations { get; set; }
public DbSet<ClaimInformation_HealthCareCode> ClaimInformation_HealthCareCode { get; set; }
}
}
public partial class ClaimInformation
{
public List<ClaimInformation_HealthCareCode> OtherDiagnosisCodes
{
get
{
return this.ClaimInformation_HealthCareCode.Where(c => c.CodeQualifier == "BF" || c.CodeQualifier == "ABF").ToList();
}
}
}
public partial class ClaimInformation
{
public ClaimInformation()
{
this.ClaimInformation_HealthCareCode = new ObservableListSource<ClaimInformation_HealthCareCode>();
}
public virtual ObservableListSource<ClaimInformation_HealthCareCode> ClaimInformation_HealthCareCode { get; set; }
}
ClaimInformation_HealthcareCodes是實體ClaimInformation上的導航屬性。在ClaimsInformation和ClaimInformation_healthcareCodes之間的1-M。一個聲明可以有許多ClaimHealthcareCodes。 這是它是如何在上下文導航屬性的跟蹤更改
_context.ClaimInformations.Include(h => h.ClaimInformation_HealthCareCode)
如何使上下文檢測的導航屬性的改變加載。在代碼中,我刪除了一個healthcareCode條目。這是ClaimInformationClass中的一個列表,並且是虛擬的。 1-M this.claiminformation.claiminfo_healthcarecodes [i] .remove();此行連接到上下文。
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;
}
此代碼返回更改的條目「ClaimInformation」這部分是真實的,但它有更深入到一個小到具有刪除的條目的導航屬性。