/// <summary> /// Refreshes an entity object according to the specified mode. /// </summary> /// <param name="mode">A value that specifies how optimistic concurrency conflicts are handled.</param> /// <param name="entities">The collection of entities to be refreshed.</param> public void Refresh(RefreshMode mode, IEnumerable entities) { CheckDispose(); CheckNotInSubmitChanges(); VerifyTrackingEnabled(); if (entities == null) { throw Error.ArgumentNull("entities"); } List <object> list = entities.Cast <object>().ToList(); DataContext context = CreateRefreshContext(); foreach (object obj2 in list) { MetaType inheritanceRoot = services.Model.GetMetaType(obj2.GetType()).InheritanceRoot; GetTable(inheritanceRoot.Type); TrackedObject trackedObject = services.ChangeTracker.GetTrackedObject(obj2); if (trackedObject == null) { throw Error.UnrecognizedRefreshObject(); } object[] keyValues = CommonDataServices.GetKeyValues(trackedObject.Type, trackedObject.Original); object objectByKey = context.Services.GetObjectByKey(trackedObject.Type, keyValues); if (objectByKey == null) { throw Error.RefreshOfDeletedObject(); } trackedObject.Refresh(mode, objectByKey); } }
private void ClearForeignKeyReferences(TrackedObject to) { foreach (MetaAssociation association in to.Type.Associations) { if ((association.IsForeignKey && (association.OtherMember != null)) && association.OtherMember.IsAssociation) { object[] foreignKeyValues = CommonDataServices.GetForeignKeyValues(association, to.Current); object instance = this.services.IdentityManager.Find(association.OtherType, foreignKeyValues); if (instance != null) { if (association.OtherMember.Association.IsMany) { IList boxedValue = association.OtherMember.MemberAccessor.GetBoxedValue(instance) as IList; if ((boxedValue != null) && !boxedValue.IsFixedSize) { boxedValue.Remove(to.Current); } } else { association.OtherMember.MemberAccessor.SetBoxedValue(ref instance, null); } } } } }
// Methods internal DeferredSourceFactory(MetaDataMember member, CommonDataServices services) { this.member = member; this.services = services; refersToPrimaryKey = this.member.IsAssociation && this.member.Association.OtherKeyIsPrimaryKey; empty = new T[0]; }
internal static ChangeTracker CreateChangeTracker(CommonDataServices dataServices, bool asReadOnly) { if (asReadOnly) { return(new ReadOnlyChangeTracker()); } return(new StandardChangeTracker(dataServices)); }
// Methods internal ChangeProcessor(CommonDataServices services, DataContext context) { this.services = services; this.context = context; this.tracker = services.ChangeTracker; this.changeDirector = services.ChangeDirector; this.currentParentEdges = new EdgeMap(); this.originalChildEdges = new EdgeMap(); this.originalChildReferences = new ReferenceMap(); }
/// <summary> /// Releases resources used by the ALinq.DataContext. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (disposing) { if (Provider != null) { Provider.Dispose(); Provider = null; } services = null; tables = null; //Source.Dispose(); } }
private void Init(object connection, MappingSource mapping) { //if (mapping is DynamicMappingSource == false) // mapping = new DynamicMappingSource(mapping); MetaModel model = mapping.GetModel(GetType()); if (providerType == null) { providerType = model.ProviderType; } if (providerType == null) { throw Error.ProviderTypeNull(); } //try //{ // LicenseManager.Validate(providerType, this); //} //catch (Exception exc) //{ // throw exc; //} services = new CommonDataServices(this, model); conflicts = new ChangeConflictCollection(); extendTableTypes = new ExtendTableTypes(); if (!typeof(IProvider).IsAssignableFrom(providerType)) { throw Error.ProviderDoesNotImplementRequiredInterface(providerType, typeof(IProvider)); } var p = (SqlProvider)Activator.CreateInstance(providerType); Provider = p; Provider.Initialize(services, connection); tables = new Dictionary <MetaTable, ITable>(); }
private bool HasAssociationChanged(MetaAssociation assoc, TrackedObject item) { if ((item.Original != null) && (item.Current != null)) { if (assoc.ThisMember.StorageAccessor.HasAssignedValue(item.Current) || assoc.ThisMember.StorageAccessor.HasLoadedValue(item.Current)) { return(this.GetOtherItem(assoc, item.Current) != this.GetOtherItem(assoc, item.Original)); } object[] foreignKeyValues = CommonDataServices.GetForeignKeyValues(assoc, item.Current); object[] objArray2 = CommonDataServices.GetForeignKeyValues(assoc, item.Original); int index = 0; int length = foreignKeyValues.Length; while (index < length) { if (!object.Equals(foreignKeyValues[index], objArray2[index])) { return(true); } index++; } } return(false); }
private TrackedObject GetOtherItem(MetaAssociation assoc, object instance) { object boxedValue; if (instance == null) { return(null); } if (assoc.ThisMember.StorageAccessor.HasAssignedValue(instance) || assoc.ThisMember.StorageAccessor.HasLoadedValue(instance)) { boxedValue = assoc.ThisMember.MemberAccessor.GetBoxedValue(instance); } else { object[] foreignKeyValues = CommonDataServices.GetForeignKeyValues(assoc, instance); boxedValue = this.services.GetCachedObject(assoc.OtherType, foreignKeyValues); } if (boxedValue == null) { return(null); } return(this.tracker.GetTrackedObject(boxedValue)); }
// Methods internal StandardChangeTracker(CommonDataServices services) { this.services = services; items = new Dictionary <object, StandardTrackedObject>(); onPropertyChanging = OnPropertyChanging; }