로드 (그 반대의 경우도 마찬가지 아니 그것에서 탐색 속성 만) 외래 키를 통해 그것을 가리키는하는 당신의 originalEntity
의 모든 관련 끝 : 당신이 좀보고 할 수 있습니다 자세한 내용은
IEnumerable<IRelatedEnd> relEnds = ((IEntityWithRelationships) originalEntity).RelationshipManager.GetAllRelatedEnds();
foreach (IRelatedEnd relatedEnd in relEnds)
{
if (relatedEnd is EntityReference)
{
continue;
}
relatedEnd.Load();
if (relatedEnd.CreateSourceQuery().OfType<EntityObject>().Any())
{
string exceptionMessage = string.Format("{0} cannot be deleted, because {1} refers to it",
originalEntity.GetType().Name,
relatedEnd.CreateSourceQuery().OfType<EntityObject>().First().GetType().Name);
throw new Exception(exceptionMessage);
}
}
MSDN에서 RelatedEnd 클래스 :
http://msdn.microsoft.com/en-us/library/system.data.objects.dataclasses.relatedend%28v=vs.110%29.aspx
// Collection of entities, you need these when iterating through entity's related ends
public class EntityCollection<TEntity> : RelatedEnd
// Models a relationship end with multiplicity 1.
public abstract class EntityReference : RelatedEnd
실행 가능한 방법처럼 보이지만 같은 그것은'DbContext'의 API 작동하지 않습니다. Esp. OfType 부분은 POCO와 함께 작동 할 수 없습니다. –
다음과 같이'DbContext'에서'ObjectContext'를 가져올 수 있습니다 :'IObjectContextAdapter adapter = (IObjectContextAdapter) dbContextInstance;' 'ObjectContext objectContext = adapter.ObjectContext;' – Andrew
@ n-rocking이 작동 했습니까? – Andrew