Grigory
Grigory

Reputation: 45

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. I've got some custom properties for EF Entity through partial class. There is a field in Database with XML type and it's mapped to Entity Framework as string. And I use partial class to deserialize this xml string to real object.

This is the partial class for EF Configuration Entity:

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. And it's not added to DomainService.metadata.cs if i create new one. 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. For example a can acess HistoryID,SourceUrl,AutomaticTransferToProductive but there are no generated properties for

public NetworkCredential Credential { get; set; } public Encoding FileEncoding { get; set; }

How can i fix this?

Upvotes: 0

Views: 165

Answers (1)

Grigory
Grigory

Reputation: 45

I've found the only way to solve this problem. The solution was just to deserialize xml field from entity framework on client-side. I've created partial class Configuration for generated code in silverlight. I don't know if it's the best solution but it works.

Upvotes: 0

Related Questions