2013-08-28 1 views
2

코드 템플릿에 의해 자동 생성되는 추상 클래스가 있습니다. 그런 다음이 클래스에서 파생 된 여러 클래스가 있습니다. 그 클래스에는 파생 된 구현 중 하나에 대해 getter 및 setter를 재정의하려는 특정 속성이 있습니다. 불행히도 가상으로 선언되지 않았으므로 속성을 무시할 방법이 없습니다.엔티티 프레임 워크 및 RIA 서비스 - 클라이언트의 공유 클래스에서 액세스 할 수없는 속성을 액세스 할 수 없습니다.

그래서 다른 접근 방식으로 속성을 보호하기로 결정한 다음 부분 클래스 (.shared.cs)에서 보호 된 속성을 효과적으로 감싸는 public 가상 속성을 만듭니다. 그런 다음 특정 구현에서이를 재정의 할 수 있습니다.

서버 쪽에서는 문제가 없지만 일단 빌드하면 클라이언트에서 생성되는 부분 공유 파일이 보호 된 속성을 볼 수없는 것으로 보입니다.

ClassA.cs는 :

//------------------------------------------------------------------------------ 
// <auto-generated> 
// This code was generated from a template. 
// 
// Manual changes to this file may cause unexpected behaviour in your application. 
// Manual changes to this file will be overwritten if the code is regenerated. 
// </auto-generated> 
//------------------------------------------------------------------------------ 

namespace ABC.Web.Models.DomainModel 
{ 
    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel.DataAnnotations; 

    [RoundtripOriginal] 
    public abstract partial class ClassA 
    { 
     public int Id { get; set; } 
     public string Title { get; set; } 
     protected string ApplicationNumber { get; set; } 
    } 
} 

ClassA.shared.cs

namespace ABC.Web.Models.DomainModel 
{ 
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Runtime.Serialization; 

    public abstract partial class ClassA 
    { 
     [IgnoreDataMember] 
     public virtual string ApplicationNumberAccessor 
     { 
      get 
      { 
       return this.ApplicationNumber; 
      } 
      set 
      { 
       this.ApplicationNumber = value; 
      } 
     } 
    } 
} 

이 효과적으로 오류를 제공 'ABC.Web.Models.DomainModel.ClassA' does not contain a definition for 'ApplicationNumber' and no extension method 'ApplicationNumber' accepting a first argument of type 'ABC.Web.Models.DomainModel.ClassA' could be found (are you missing a using directive or an assembly reference?)

는 일부 경우 파일의 클라이언트 버전에 나를 소요되는 오류를 더블 클릭 보호 된 재산을 볼 수없는 이유.

왜 그런가? 또는 다른 방법으로 (데이터베이스를 먼저 사용하여) 필드를 표시하여 가상으로 생성하는 방법이 있습니까?

답변

1

구성원이 serialize되지 않은 경우 WCF RIA는 Web.g.cs에 구성원을 만들지 않습니다. ApplicationNumber은 보호 된 속성이므로 WCF RIA는이를 무시합니다. 이것은 웹 프로젝트에서 컴파일되는 이유를 설명하지만 Silverlight에서는 컴파일되지 않습니다.

아니요,은 다른 부분을 공유하지만 대신 속성을 추가 했습니까?

ClassA.cs 또는 ClassA.partial.cs로 변경을하고하는 내용 :

namespace ABC.Web.Models.DomainModel 
{ 
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Runtime.Serialization; 

    public abstract partial class ClassA 
    { 
     // You _do_ want this serialized to the client and back 
     // so remove the [IgnoreDataMember] atribute 
     public virtual string ApplicationNumberAccessor 
     { 
      get 
      { 
       return this.ApplicationNumber; 
      } 
      set 
      { 
       this.ApplicationNumber = value; 
      } 
     } 
    } 
} 
+0

감사 에드! IgnoreDataMember는 ApplicationNumber에서 값을 가져 왔으므로 값을 두 번 보내지 않아야합니다. 하지만이 방법은 아직 한 번만 보내고 있습니다. RIA가 액세서 값을 서버로 다시 보낼 때 ApplicationNumber가 클라이언트에 존재할 필요가 없으므로 ApplicationNumber를 업데이트 할 서버 클래스의 접근 자 값을 설정하므로 제대로 유지됩니다. 이제는 분명히 보았습니다. – SteveL

관련 문제