public static EntityKey CreateKeyFromForeignKeyValues( EntityEntry dependentEntry, ReferentialConstraint constraint, EntitySet principalEntitySet, bool useOriginalValues) { ReadOnlyMetadataCollection <EdmProperty> toProperties = constraint.ToProperties; int count = toProperties.Count; if (count == 1) { object singletonKeyValue = useOriginalValues ? dependentEntry.GetOriginalEntityValue(toProperties.First <EdmProperty>().Name) : dependentEntry.GetCurrentEntityValue(toProperties.First <EdmProperty>().Name); if (singletonKeyValue != DBNull.Value) { return(new EntityKey((EntitySetBase)principalEntitySet, singletonKeyValue)); } return((EntityKey)null); } string[] keyMemberNames = principalEntitySet.ElementType.KeyMemberNames; object[] compositeKeyValues = new object[count]; ReadOnlyMetadataCollection <EdmProperty> fromProperties = constraint.FromProperties; for (int index1 = 0; index1 < count; ++index1) { object obj = useOriginalValues ? dependentEntry.GetOriginalEntityValue(toProperties[index1].Name) : dependentEntry.GetCurrentEntityValue(toProperties[index1].Name); if (obj == DBNull.Value) { return((EntityKey)null); } int index2 = Array.IndexOf <string>(keyMemberNames, fromProperties[index1].Name); compositeKeyValues[index2] = obj; } return(new EntityKey((EntitySetBase)principalEntitySet, compositeKeyValues)); }
private static string GetTableNameByClrName(ReadOnlyMetadataCollection<EntitySet> EntitySets,string tablename) { return EntitySets.First(x=>x.Name == tablename).Table; }