private bool HasDeferredLoader(MetaDataMember deferredMember) { if (!deferredMember.IsDeferred) { return(false); } MetaAccessor acc = deferredMember.StorageAccessor; if (acc.HasAssignedValue(this.current) || acc.HasLoadedValue(this.current)) { return(false); } MetaAccessor dsacc = deferredMember.DeferredSourceAccessor; IEnumerable loader = (IEnumerable)dsacc.GetBoxedValue(this.current); return(loader != null); }
private void InitializeDeferredLoader(MetaDataMember deferredMember) { MetaAccessor acc = deferredMember.StorageAccessor; if (!acc.HasAssignedValue(this.current) && !acc.HasLoadedValue(this.current)) { MetaAccessor dsacc = deferredMember.DeferredSourceAccessor; IEnumerable loader = (IEnumerable)dsacc.GetBoxedValue(this.current); // don't reset loader on any deferred member that already has one if (loader == null) { IDeferredSourceFactory factory = this.tracker.services.GetDeferredSourceFactory(deferredMember); loader = factory.CreateDeferredSource(this.current); dsacc.SetBoxedValue(ref this.current, loader); } else if (loader != null && !haveInitializedDeferredLoaders) { // If loader is present but wasn't generated by us, then // an attempt to Attach or Add an entity from another context // has been made, which is not supported. throw Error.CannotAttachAddNonNewEntities(); } } }
private void AutoSyncMembers(object[] syncResults, TrackedObject item, UpdateType updateType, AutoSyncBehavior autoSyncBehavior) { System.Diagnostics.Debug.Assert(item != null); System.Diagnostics.Debug.Assert(item.IsNew || item.IsPossiblyModified, "AutoSyncMembers should only be called for new and modified objects."); object[] syncRollbackValues = null; if (syncResults != null) { int idx = 0; var membersToSync = GetAutoSyncMembers(item.Type, updateType); System.Diagnostics.Debug.Assert(syncResults.Length == membersToSync.Count); if (autoSyncBehavior == AutoSyncBehavior.ApplyNewAutoSync) { syncRollbackValues = new object[syncResults.Length]; } foreach (MetaDataMember mm in membersToSync) { object value = syncResults[idx]; object current = item.Current; MetaAccessor accessor = (mm.Member is PropertyInfo && ((PropertyInfo)mm.Member).CanWrite) ? mm.MemberAccessor : mm.StorageAccessor; if (syncRollbackValues != null) { syncRollbackValues[idx] = accessor.GetBoxedValue(current); } accessor.SetBoxedValue(ref current, DBConvert.ChangeType(value, mm.Type)); idx++; } } if (syncRollbackValues != null) { this.SyncRollbackItems.Add(new KeyValuePair <TrackedObject, object[]>(item, syncRollbackValues)); } }