ak1
ak1

Reputation: 379

datacontract property becomes readonly at client side - WCF RIA

Here is a DataContract in WCF RIA Services Layer...

[Serializable()]
[DataContract]
public class MyDataSet
{
    [Include]
    [Association("ListTables", "DataSetName", "DataSetName")]
    [DataMember]
    public Collection<DataTableInfo> Tables { get; set; }

    [Key]
    [DataMember]
    public string DataXML { get; set; }

    [DataMember]
    public string DataSetName { get; set; }
}

On the client side, in a view model, I create a new instance of this DataContract and tries to assign any values to the Tables property, I get ans error that this property is readonly.

I need to understand the reason and a workaround of this issue...

Thanks

Upvotes: 0

Views: 339

Answers (1)

Ed Chapel
Ed Chapel

Reputation: 6932

You probably have a DomainService with a query like:

[EnableClientAccess]
public class MyDomainService : DomainService
{
    public IQueryable<MyDataSet> GetMyDataSets()
    {
        /* return something; */
    }
}

Unless you have methods for Insert and/or Update, WCF RIA has no way of updating the entity and assumes you intended for it to be read-only. Try adding these methods:

public void CreateMyDataSet(MyDataSet entity)
{
    // Insert
}

public void UpdateMyDataSet(MyDataSet entity)
{
    // Update
}

public void RemoveMyDataSet(MyDataSet entity)
{
    // Delete
}

Upvotes: 1

Related Questions