private void UpdateIdentities(OeLinq2DbTable table, int lastIndex) { if (table.Identities.Count == 0) { return; } foreach (IEdmNavigationPropertyBinding navigationBinding in _orderedTableTypes[lastIndex].EdmEntitySet.NavigationPropertyBindings) { if (navigationBinding.NavigationProperty.IsPrincipal() || navigationBinding.NavigationProperty.Partner == null) { for (int j = 0; j <= lastIndex; j++) { if (_orderedTableTypes[j].EdmEntitySet == navigationBinding.Target) { List <PropertyInfo> dependentProperties = GetDependentProperties(_orderedTableTypes[j].ClrTableType, navigationBinding.NavigationProperty); OeLinq2DbTable targetTable = GetTable(_orderedTableTypes[j].ClrTableType); targetTable.UpdateIdentities(dependentProperties[0], table.Identities); if (targetTable.IsKey(dependentProperties[0])) { foreach (PropertyInfo dependentProperty in GetDependentProperties(dependentProperties[0], _orderedTableTypes, j)) { GetTable(dependentProperty.DeclaringType).UpdateIdentities(dependentProperty, table.Identities); } } break; } } } } }
public int SaveChanges(DataConnection dataConnection) { int count = 0; for (int i = _orderedTableTypes.Length - 1; i >= 0; i--) { OeLinq2DbTable table = GetTable(_orderedTableTypes[i].ClrTableType); if (table != null) { count += table.SaveInserted(dataConnection); UpdateIdentities(table, i); count += table.SaveUpdated(dataConnection); } } for (int i = 0; i < _orderedTableTypes.Length; i++) { OeLinq2DbTable table = GetTable(_orderedTableTypes[i].ClrTableType); if (table != null) { count += table.SaveDeleted(dataConnection); } } return(count); }
internal OeLinq2DbTable <T> GetTable <T>() where T : class { if (_tables.TryGetValue(typeof(T), out OeLinq2DbTable value)) { return((OeLinq2DbTable <T>)value); } var table = new OeLinq2DbTable <T>(); _tables.Add(typeof(T), table); return(table); }
public OeLinq2DbTable <T> GetTable <T>() { OeLinq2DbTable value; if (_tables.TryGetValue(typeof(T), out value)) { return((OeLinq2DbTable <T>)value); } var table = new OeLinq2DbTable <T>(); _tables.Add(typeof(T), table); return(table); }
private void UpdateIdentities(OeLinq2DbTable table, List <ClrTypeEdmSet> clrTypeEdmSetList, int lastIndex) { if (table.Identities.Count == 0) { return; } foreach (IEdmNavigationPropertyBinding navigationBinding in clrTypeEdmSetList[lastIndex].EdmSet.NavigationPropertyBindings) { if (navigationBinding.NavigationProperty.IsPrincipal()) { for (int j = 0; j <= lastIndex; j++) { if (clrTypeEdmSetList[j].EdmSet == navigationBinding.Target) { var dependentProperties = GetDependentProperties(clrTypeEdmSetList[j].ClrType, navigationBinding.NavigationProperty); GetTable(clrTypeEdmSetList[j].ClrType).UpdateIdentities(dependentProperties.Single(), table.Identities); break; } } } } }
public int SaveChanges(IEdmModel edmModel, OeEntitySetMetaAdapterCollection entitySetMetaAdapters, DataConnection dataConnection) { List <ClrTypeEdmSet> clrTypeEdmSetList = GetClrTypeEdmSetList(edmModel, entitySetMetaAdapters); int count = 0; for (int i = clrTypeEdmSetList.Count - 1; i >= 0; i--) { OeLinq2DbTable table = GetTable(clrTypeEdmSetList[i].ClrType); count += table.SaveInserted(dataConnection); UpdateIdentities(table, clrTypeEdmSetList, i); count += table.SaveUpdated(dataConnection); } for (int i = 0; i < clrTypeEdmSetList.Count; i++) { OeLinq2DbTable table = GetTable(clrTypeEdmSetList[i].ClrType); count += table.SaveDeleted(dataConnection); } return(count); }