2012-05-22 1 views
0

2 개의 테이블에 1-1 관계가 있습니다.LINQ에서 .Include()를 사용하여 하위 테이블 엔터티를 속성에 전달하려고합니다. 부모 테이블의 필드와 함께 자식 테이블 필드를 표에 바인딩 할 수 있습니다. 원래는 이렇게 잘 작동하고 그리드에 바인딩 할 수 있지만 BUGroupBuildings 테이블에서만 결과를 얻을 수 있습니다. 또한 vwBuisnessUnits 테이블의 필드에 바인딩해야합니다.Silverlight 4 (RIA 포함) - 테이블 필드를 표로 결합했습니다.

Load operation failed for query 'GetBusinessUnitsBasedOnGroupID'. A specified Include path is not valid. The EntityType 'EQUITYDWModel.BUGroupBuilding' does not declare a navigation property with the name 'vwBuisnessUnits'

여기 내 기업의 enter image description here

내가 추가 한 : 나는 to bring back child table fields을 포함 사용하는 전환하면

public IQueryable<BUGroupBuilding> GetBusinessUnitsBasedOnGroupID(int i) 
    { 
     var result = from d in this.ObjectContext.BUGroupBuildings 
        join b in this.ObjectContext.vwBusinessUnits on d.BU equals b.BU 
        where d.BUGroupID == i 
        orderby d.BU ascending 
        select d; 

     return result; 

    } 

, 나는

public IQueryable<BUGroupBuilding> GetBusinessUnitsBasedOnGroupID(int i) 
    { 
     var result = from d in this.ObjectContext.BUGroupBuildings 
        .Include("vwBuisnessUnits") 
        select d; 
     result = result.Where(w => w.BUGroupID == i).OrderBy(o => o.vwBusinessUnit.BU); 

     return result; 

    } 

가 ERROR 오류를 얻을 메타 데이터에 필요한 [Include].

[MetadataTypeAttribute(typeof(BUGroupBuilding.BUGroupBuildingMetadata))] 
public partial class BUGroupBuilding 
{ 

    internal sealed class BUGroupBuildingMetadata 
    { 

     // Metadata classes are not meant to be instantiated. 
     private BUGroupBuildingMetadata() 
     { 
     } 

     public string BU { get; set; } 
     [Include] 
     public BUGroup BUGroup { get; set; } 

     public int BUGroupBuildingsID { get; set; } 

     public Nullable<int> BUGroupID { get; set; } 
     [Include] 
     public vwBusinessUnit vwBusinessUnit { get; set; } 

    } 
} 
+1

탐색 속성이 vwBusinessUnit 인 경우 왜'.Include ("vwBuisnessUnits")'를 사용합니까? 철자? – Zabavsky

+0

vwBusinessUnits가 내 자식 테이블 이름입니다. Inlcude에서 내비게이션 이름을 사용한다고 가정합니까? – stevenjmyu

+0

Include ("vwBusinessUnit")로 업데이트되었지만 'GetBusinessUnitsBasedOnGroupID'쿼리에 대해로드 작업을 수행하지 못했습니다. 지정한 포함 경로가 유효하지 않습니다. EntityType 'EQUITYDWModel.BUGroupBuilding'이 (가) 'vwBuisnessUnit'이라는 이름의 탐색 속성을 선언하지 않습니다. – stevenjmyu

답변

1

db에서 EntityModel을 생성했거나 수동으로 생성 했습니까? 메타 데이터 클래스를 수동으로 만들었습니까?

아마도 일부 잘못되었습니다. 다음과 같이 클라이언트 측 (Web.g.cs 파일)에 탐색 속성을 작성해야합니다.

/// <summary> 
     /// Gets or sets the associated <see cref="tblCustomer"/> entity. 
     /// </summary> 
     [Association("tblCustomer_tblInvoice", "uiCustomerId", "Id", IsForeignKey=true)] 
     [XmlIgnore()] 
     public tblCustomer tblCustomer 
     { 
      get 
      { 
       if ((this._tblCustomer == null)) 
       { 
        this._tblCustomer = new EntityRef<tblCustomer>(this, "tblCustomer", this.FiltertblCustomer); 
       } 
       return this._tblCustomer.Entity; 
      } 
      set 
      { 
       tblCustomer previous = this.tblCustomer; 
       if ((previous != value)) 
       { 
        this.ValidateProperty("tblCustomer", value); 
        if ((previous != null)) 
        { 
         this._tblCustomer.Entity = null; 
         previous.tblInvoices.Remove(this); 
        } 
        if ((value != null)) 
        { 
         this.uiCustomerId = value.Id; 
        } 
        else 
        { 
         this.uiCustomerId = default(Guid); 
        } 
        this._tblCustomer.Entity = value; 
        if ((value != null)) 
        { 
         value.tblInvoices.Add(this); 
        } 
        this.RaisePropertyChanged("tblCustomer"); 
       } 
      } 
     } 

엔티티 모델 및 관계를 확인하십시오.

+0

Mr. Zabavsky. 오류 설명을 잃어 버렸습니다. –

1

Ahhh. 내 문제에 대한 해결책을 찾았습니다. 나는 그것을 공동체와 나눌 것이라고 생각했다. 두 엔티티 (내 경우,보기 및 테이블) 사이에 사용자 지정 관계가있을 때 linq 쿼리에서 조인과 Inlcude를 수행해야한다는 것이 밝혀졌습니다. 관계가 모델에 정의되면 명시 적 조인이 필요하지 않습니다.

public IQueryable<BUGroupBuilding> GetBusinessUnitsBasedOnGroupID(int i) 
    { 
     var result = from d in this.ObjectContext.BUGroupBuildings 
        join b in this.ObjectContext.vwBusinessUnits on d.BU equals b.BU 
        where d.BUGroupID == i 
        orderby d.BU ascending 
        select d; 


     var r2 = from d2 in ((ObjectQuery<BUGroupBuilding>)result) 
       .Include("vwBusinessUnit") 
       select d2; 

     return r2;    
    } 
관련 문제