2012-10-03 2 views
0

클라이언트 응용 프로그램으로 Entity Framework 및 Silverlight와 함께 RIA 서비스를 사용하고 있습니다. 부분 클래스를 통해 EF 엔터티에 대한 몇 가지 사용자 지정 속성이 있습니다. XML 형식의 데이터베이스에는 필드가 있으며 Entity Framework에 문자열로 매핑됩니다. 그리고 난 부분 클래스를 사용하여이 XML 문자열을 실제 객체로 역 직렬화합니다.부분 클래스 및 복잡한 유형의 Silvelight 및 RIA 서비스 및 Entity Framework 문제

이 EF 구성 엔티티에 대한 부분 클래스입니다 :

public partial class Configuration 
{ 
    private ServiceCredentials _serviceCredentialsObject; 

    [DataMember] 
    public ServiceCredentials ServiceCredentialsObject 
    { 
     get 
     { 
      return this._serviceCredentialsObject 
        ?? (this._serviceCredentialsObject = this.DeserializeServiceCredentialsToObject()); 
     } 

     set 
     { 
      this._serviceCredentialsObject = value; 
      this.SerializeServiceCredentialsObject(); 
     } 
    } 

    public ServiceCredentials DeserializeServiceCredentialsToObject() 
    { 
     if (string.IsNullOrEmpty(this.ServiceCredentials)) 
     { 
      return null; 
     } 

     var result = XmlSerializerHelper.Deserialize<ServiceCredentials>(this.ServiceCredentials); 
     result.FileEncoding = result.FileEncoding ?? Encoding.UTF8; 

     return result; 
    } 

    public void SerializeServiceCredentialsObject() 
    { 
     if (this.ServiceCredentialsObject == null) 
     { 
      this.ServiceCredentials = null; 
      return; 
     } 

     this.ServiceCredentials = XmlSerializerHelper.Serialize(this.ServiceCredentialsObject); 
    } 

} 

는 그리고 이것은 내가 역 직렬화하기 위해 노력하고있어 객체입니다

[Serializable] 
public class ServiceCredentials 
{ 

    public NetworkCredential Credential { get; set; } 

    public Encoding FileEncoding { get; set; } 

    [XmlIgnore] 
    public long HistoryID { get; set; } 

    public string LoadFileStoragePath { get; set; } 

    public string ManualLoadFilePath { get; set; } 

    public bool NeedAuthorization { get; set; } 

    [XmlIgnore] 
    public string ProviderID { get; set; } 

    public string SourceUrl { get; set; } 

    public bool AutomaticTransferToProductive { get; set; } 
} 

나는에 구성 엔티티를 사용하려고 해요 생성 된 코드가있는 silverlight 클라이언트 쪽에서 Configuration 클래스에 ServiceCredentialsObject가 없다는 문제를 찾습니다. 그리고 새로 만들면 DomainService.metadata.cs에 추가되지 않습니다. ServiceCredentialsObject를 수동으로 DomainService.metadata.cs에 추가하면 clien-side에서 재구성 한 후 액세스 할 수 있지만 간단한 유형의 속성 만 찾을 수 있습니다. 예를 들어, HistoryID, SourceUrl, AutomaticTransferToProductive을 처리 할 수 ​​있지만 생성 된 속성은 없습니다.

public NetworkCredential Credential {get; 세트; } 공용 인코딩 FileEncoding {get; 세트; }

어떻게 해결할 수 있습니까?

답변

0

이 문제를 해결할 수있는 유일한 방법을 찾았습니다. 솔루션은 클라이언트 측의 엔티티 프레임 워크에서 XML 필드를 deserialize하는 것이 었습니다. 실버 라이트에서 생성 된 코드에 대한 partial class Configuration을 만들었습니다. 나는 그것이 최선의 해결책인지는 모르겠지만 작동한다.