컨텍스트의 아이디어는 너무 커지지 않도록하는 것입니다. 서로 다른 데이터보기를 통해 여러 컨텍스트를 보유 할 수도 있습니다. 작업 단위 (Unit of Work) 당 새로운 컨텍스트를 사용하는 경우에도 적용됩니다. 그래, 큰 얻을 수 있습니다. 이 주제에 대한 좋은 읽을 거리 제한된 컨텍스트와 루 패턴을 검색하십시오. 예를 들면 Julie Lerman.
다음은 EF (EF5.0/Net 4.0)가 관리하는 디 컴파일 된 IEntityWrapper입니다. IENtityWrapper는 ObjectContext에 엔터티를 넣을 때 사용됩니다.
큰지를 결정하게합니다. AS 기준 Millimetric 언급
는 object Entity { get; } // see below inside wrapper
internal interface IEntityWrapper
{
void EnsureCollectionNotNull(RelatedEnd relatedEnd);
EntityKey GetEntityKeyFromEntity();
void AttachContext(ObjectContext context, EntitySet entitySet, MergeOption mergeOption);
void ResetContext(ObjectContext context, EntitySet entitySet, MergeOption mergeOption);
void DetachContext();
void SetChangeTracker(IEntityChangeTracker changeTracker);
void TakeSnapshot(EntityEntry entry);
void TakeSnapshotOfRelationships(EntityEntry entry);
void CollectionAdd(RelatedEnd relatedEnd, object value);
bool CollectionRemove(RelatedEnd relatedEnd, object value);
object GetNavigationPropertyValue(RelatedEnd relatedEnd);
void SetNavigationPropertyValue(RelatedEnd relatedEnd, object value);
void RemoveNavigationPropertyValue(RelatedEnd relatedEnd, object value);
void SetCurrentValue(EntityEntry entry, StateManagerMemberMetadata member, int ordinal, object target, object value);
void UpdateCurrentValueRecord(object value, EntityEntry entry);
RelationshipManager RelationshipManager { get; }
bool OwnsRelationshipManager { get; }
object Entity { get; }
EntityEntry ObjectStateEntry { get; set; }
EntityKey EntityKey { get; set; }
ObjectContext Context { get; set; }
MergeOption MergeOption { get; }
Type IdentityType { get; }
bool InitializingProxyRelatedEnds { get; set; }
bool RequiresRelationshipChangeTracking { get; }
}
/// <summary>
/// Adds an object to the object context.
/// </summary>
/// <param name="entitySetName">Represents the entity set name, which may optionally be qualified by the entity container name. </param><param name="entity">The <see cref="T:System.Object"/> to add.</param><exception cref="T:System.ArgumentNullException">The <paramref name="entity"/> parameter is null. -or-The <paramref name="entitySetName"/> does not qualify.</exception>
public void AddObject(string entitySetName, object entity)
{
EntityUtil.CheckArgumentNull<object>(entity, "entity");
EntityEntry existingEntry;
IEntityWrapper wrappedEntity = EntityWrapperFactory.WrapEntityUsingContextGettingEntry(entity, this, out existingEntry);
if (existingEntry == null)
this.MetadataWorkspace.ImplicitLoadAssemblyForType(wrappedEntity.IdentityType, (Assembly) null);
EntitySet entitySet;
bool isNoOperation;
this.VerifyRootForAdd(false, entitySetName, wrappedEntity, existingEntry, out entitySet, out isNoOperation);
if (isNoOperation)
return;
System.Data.Objects.Internal.TransactionManager transactionManager = this.ObjectStateManager.TransactionManager;
transactionManager.BeginAddTracking();
try
{
RelationshipManager relationshipManager = wrappedEntity.RelationshipManager;
bool flag = true;
try
{
this.AddSingleObject(entitySet, wrappedEntity, "entity");
flag = false;
}
finally
{
if (flag && wrappedEntity.Context == this)
{
EntityEntry entityEntry = this.ObjectStateManager.FindEntityEntry(wrappedEntity.Entity);
if (entityEntry != null && entityEntry.EntityKey.IsTemporary)
{
relationshipManager.NodeVisited = true;
RelationshipManager.RemoveRelatedEntitiesFromObjectStateManager(wrappedEntity);
RelatedEnd.RemoveEntityFromObjectStateManager(wrappedEntity);
}
}
}
relationshipManager.AddRelatedEntitiesToObjectStateManager(false);
}
finally
{
transactionManager.EndAddTracking();
}
}
이 게시물을 변경 추적 포항 강판 작동 방법에 대한 자세한 내용을 설명합니다. http://blogs.msdn.com/b/adonet/archive/2009/06/10/poco-in-the-entity-framework-part-3-change-tracking-with-poco.aspx –
@ MalcolmO'Hare , 나는 기사를 통해 탈지 만 나는이 특별한 경우에 대해서 이야기하는 것처럼 보이지 않는다. –