2011-08-28 4 views
2

나는 서버쪽에 채우고 클라이언트에게 보낼 다른 DTO 안에 컬렉션이있는 DTO를 가지고 있습니다. 그러나이 내부 DTO 컬렉션은 클라이언트에 반환되지 않습니다.DTO 및 WCF RIA

WCF RIA 서비스가 무엇을해야하는지 알 수 있도록 [포함] 및 [연관] 속성을 사용해야한다고 생각합니다. 그러나이 문제는 주 DTO와 내부 DTO 사이에 실제 연관성이 없습니다. 콜렉션에서 클라이언트로 리턴하기 위해 다양한 소스의 데이터를 집계하는 데 사용하고 있습니다.

WCF RIA에서이 내부 DTO 컬렉션을 보내려면 어떻게해야합니까?

필자는 automapper를 사용하고 있으며이를 사용하여이를 달성하고자한다고 덧붙여 야합니다.

다음은 예입니다. 하나의 청크로 클라이언트로 다시 보내고 싶습니다.

  1. 직원의 역량.
  2. 직원이 직무에 요구하는 역량.
  3. 1
public class CompetencyRequirementsDto 
{ 
    [Key] 
    public string CompanyId { get; set; } 
    [Key] 
    public string EmployeeNo { get; set; } 

    public string JobId { get; set; } 

    [Include] 
    [Association("EmployeeCompetencies","CompanyId, EmployeeNo","CompanyId, EmployeeNo")] 
    public IList<EmployeeCompetencyDto> EmployeeCompetencies { get; set; } 
    [Include] 
    [Association("JobCompetencies","JobId, CompanyId","JobId, CompanyId")] 
    public IList<JobCompetencyDto> JobCompetencies { get; set; } 
    [Include] 
    [Association("CompetencyGap", "JobId, CompanyId", "JobId, CompanyId")] 
    public IList<JobCompetencyDto> CompetencyGap { get; set; } 
} } 
2의 차이는

지금 1 개 작품 잘 항목,하지만 2, 3 안 인 GAP,? 내가 찾은 바는 내 DTO가 서버 측에서 만들어졌지만 CompetencyGap (값이없는 경우에도)에 도달하면 에 JobCompetencies 값이 주어 졌다고합니다.

+0

일부 코드가 포함 된 경우? 리아 서비스를 생성 했습니까? 직접 작성 했습니까? linq2sql 또는 엔티티 프레임 워크를 사용 했습니까? – Geoff

+0

리오 서비스는 약간의 수작업을 통해 생성되었습니다. DTO의 진정한 의미에서 RIA와 함께 DTO를 사용하는 방법에 대한 일반적인 질문입니다. 즉, 데이터가 필요 이상으로 관련이없는 데이터 버킷입니다. 그러나 내 안의 DTO가 부모 DTO와 연관 될 필요가 있다는 것을 알기까지는 말입니다. 감사. – David

+0

코드를 보여줄 수 있습니까? 아마도 더 간단한 DTO 개체 세트로 문제를 복제하고 붙여 넣으려고합니까? –

답변

0

ADO.Net 엔터티 데이터 모델을 사용하고 RIA 서비스를 사용하는 경우 관련 메타 데이터를 만들 수있는 옵션이 있습니다.

클라이언트 측 참조 엔터티를 얻으려면 해당 메타 데이터와 데이터를 가져 오는 도메인 서비스 클래스의 기능을 모두 수정해야합니다.

Here I am giving an example... 

1. Just add [Include] attribute at the the top of the referenced data for example. 

[MetadataTypeAttribute(typeof(Customer.CustomerMetadata))] 
    public partial class Customer 
    { 

     // This class allows you to attach custom attributes to properties 
     // of the Customer class. 
     // 
     // For example, the following marks the Xyz property as a 
     // required property and specifies the format for valid values: 
     // [Required] 
     // [RegularExpression("[A-Z][A-Za-z0-9]*")] 
     // [StringLength(32)] 
     // public string Xyz { get; set; } 
     internal sealed class CustomerMetadata 
     { 

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

      public int CustomerID { get; set; } 

      public string EmailAddress { get; set; } 

      public string FullName { get; set; } 

      [Include] 
      public EntityCollection<Order> Orders { get; set; } 

      public string Password { get; set; } 
     } 
    } 


2. Modify the function in the domain service and add include there also for example. 

    public IQueryable<Customer> GetCustomers() 
     { 
      var res = this.ObjectContext.Customers.Include("Orders"); 
      return res; 
     } 

    In your case the first part is done you just need to modify your domain service query to get reference entities.