简体   繁体   English

Silvelight&RIA Services&Entity Framework存在局部类和复杂类型的问题

[英]Silvelight&RIA Services&Entity Framework problems with partial classes and complex types there

I'm using RIA Services with Entity Framework and Silverlight as the client Application. 我正在将RIA Services与Entity Framework和Silverlight用作客户端应用程序。 I've got some custom properties for EF Entity through partial class. 我已经通过部分类为EF实体提供了一些自定义属性。 There is a field in Database with XML type and it's mapped to Entity Framework as string. 数据库中有一个XML类型的字段,它作为字符串映射到Entity Framework。 And I use partial class to deserialize this xml string to real object. 而且我使用部分类将该XML字符串反序列化为真实对象。

This is the partial class for EF Configuration Entity: 这是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);
    }

}

And this is the object i'm trying to Deserialize: 这是我要反序列化的对象:

[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; }
}

When I'm trying to use Configuration Entity on silverlight client-side with generated code find an issue that there is no ServiceCredentialsObject in Configuration class. 当我尝试在Silverlight客户端上将Configuration Entity与生成的代码一起使用时,发现Configuration类中没有ServiceCredentialsObject的问题。 And it's not added to DomainService.metadata.cs if i create new one. 如果我创建一个新文件,则不会将其添加到DomainService.metadata.cs中。 If i add ServiceCredentialsObject to DomainService.metadata.cs manually i can access it on clien-side after rebuild but i can find only properties with simple types there. 如果我将ServiceCredentialsObject手动添加到DomainService.metadata.cs,则可以在重建后在客户端上访问它,但在那里只能找到具有简单类型的属性。 For example a can acess HistoryID,SourceUrl,AutomaticTransferToProductive but there are no generated properties for 例如,可以访问HistoryID,SourceUrl,AutomaticTransferToProductive,但没有生成的属性

public NetworkCredential Credential { get; 公共NetworkCredential凭据{get; set; 组; } public Encoding FileEncoding { get; } public Encoding FileEncoding {get; set; 组; } }

How can i fix this? 我怎样才能解决这个问题?

I've found the only way to solve this problem. 我找到了解决此问题的唯一方法。 The solution was just to deserialize xml field from entity framework on client-side. 解决方案只是在客户端从实体框架反序列化xml字段。 I've created partial class Configuration for generated code in silverlight. 我已经在Silverlight中为生成的代码创建了部分类Configuration。 I don't know if it's the best solution but it works. 我不知道这是否是最好的解决方案,但是它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM