0

내 EF5 엔터티 모델을 노출하는 WCF 데이터 서비스가 있습니다. 이 특정 모델에는 두 개의 자체 참조 열이 있습니다. 아래는 모델입니다.데이터 서비스에서 Entity Framework 5 (EF5)를 사용하여 자체 참조 엔터티를 사용하는 동안 오류가 발생했습니다.

public class Chunk 
{ 
    [Key] 
    public int Id { get; set; } 

    [Required] 
    public string Name { get; set; } 

    /// <summary> 
    /// Gets/sets the left chunk, which is used for chaining 
    /// </summary> 
    public int? LeftChunk_Id { get; set; } 

    /// <summary> 
    /// Gets/sets the right chunk, which is used for chaining 
    /// </summary> 
    public int? RightChunk_Id { get; set; } 

    /// <summary> 
    /// Gets/set any chunk that should be rendered to the left of this chunk 
    /// </summary> 
    [ForeignKey("LeftChunk_Id")] 
    public virtual Chunk Left { get; set; } 

    /// <summary> 
    /// Gets/sets any chunk that should be rendered to the right of this chunk 
    /// </summary> 
    [ForeignKey("RightChunk_Id")] 
    public virtual Chunk Right { get; set; } 
} 

또한 Fluent를 사용하여 관계를 설정합니다.

modelBuilder.Entity<Chunk>() 
    .HasOptional<Chunk>(o => o.Left) 
    .WithMany() 
    .HasForeignKey(o => o.LeftChunk_Id) 
    .WillCascadeOnDelete(false); 

modelBuilder.Entity<Chunk>() 
    .HasOptional<Chunk>(o => o.Right) 
    .WithMany() 
    .HasForeignKey(o => o.RightChunk_Id) 
    .WillCascadeOnDelete(false); 

데이터 모델을 노출하는 WCF 데이터 서비스가 있습니다. 종속 역할 Chunk_Left_Source에 의해 참조

등록이의 키의 하위 집합이어야합니다 :

public class ContentStudio : DataService<ObjectContext> 
{ 
    public static void InitializeService(DataServiceConfiguration config) 
    { 
     config.SetEntitySetAccessRule("Chunks", EntitySetRights.AllRead); 

     config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; 
    } 

    protected override ObjectContext CreateDataSource() 
    { 
     ContentStudioDataContext ctx = new ContentStudioDataContext(); 

     var objectContext = ((IObjectContextAdapter)ctx).ObjectContext; 

     objectContext.ContextOptions.ProxyCreationEnabled = false; 
     return objectContext; 
    } 
} 

내가 샘플 응용 프로그램에서이 데이터 서비스에 연결을 시도

는, 다음과 같은 메시지가 뜹니다 관계 MyNamespace.Chunk_Left에 대한 참조 제한에서 종속 역할 에 의해 참조 된 EntityType MyNamespace.Chunk.

동일한 메시지가 Chunk.Right에 대해 반복됩니다. 이것은 EF5에서만 발생합니다. EF 4.3.1로 다운 그레이드하면 작동합니다. VS 2012와 .NET 4.5를 사용하고 있습니다. 아무도 내가 이걸 도와 주면 정말 고마워.

답변

0

그래서 .NET 4.5와 함께 제공되는 System.Data.Services 라이브러리 대신 Microsoft.Data.Services 라이브러리를 업그레이드하는 것이 좋습니다. 이 문제가이 문제를 놓고 비틀 거리는 사람에게 도움이되기를 바랍니다.