Kamarey
Kamarey

Reputation: 11079

Silverlight + RIA: problem editing entity

I have a Silverlight 4 application with EntityFramework as data layer.

There are two entities: Customer and Products. When I get customer from a database, the related products are also read, as I added related 'Include' attribute in customer's metadata and call Include method in get query:

public IQueryable<customer> GetCustomerSetById(int customerId)
{
    return this.ObjectContext.CustomerSet
        .Include(o => o.Products)
        .Where(o => o.Id = customerId);
}

The problem that when I change any property in customer's product I get this exception:

This EntitySet of Type 'MyApp.Web.Models.Product' does not support the 'Edit' operation.

But everything works if I read customer products directly, e.g. not through customer entity (CustomerContext) , but via product one (ProductContext).

Also there is the IsReadOnly=true property in a product entity.

UPDATE:

I have all CUD operations and also marked all of them with related Insert, Update and Delete attributes. Otherwise it wouldn't work at all, but it works for me in some cases as I wrote above.

Any ideas?

Upvotes: 3

Views: 2007

Answers (4)

Akash Kava
Akash Kava

Reputation: 39946

This is the real problem with RIA+EF so we keep all our entities in one domain service because at client side it is difficult to deal with multiple entities related via navigation properties. Think for a minute it actually makes no difference and we use EF T4 template to generate all domain service operation in one class. And we generated partial methods to intercept logic of domain service methods.

Upvotes: 2

JBrooks
JBrooks

Reputation: 10013

Have you tried moving the Include to the end?

Return this.ObjectContext.CustomerSet
        .Include(o => o.Products)
        .Where(o => o.Id = customerId);

Could be:

Return (from o in this.ObjectContext.CustomerSet
        where o.Id = customerId
        select o).Include("Products");

Upvotes: 0

BentOnCoding
BentOnCoding

Reputation: 28208

RIA Services EntitySet does not support 'Edit' operation

Since the aforementioned solutions do not appear to be helping try using this:

Domain Service Wizard

This wizard should look at your entity, and generate the appropriate CRUD operations. If you then cant update your entities you have a different problem.

Upvotes: 0

grimus
grimus

Reputation: 3175

It sounds like you need to make sure you have an update operation in your domain service. It will look something like this:

public void UpdateProduct(Product product)
{
    ObjectContext.Products.AttachAsModified(product, ChangeSet.GetOriginal(product));
}

Upvotes: 0

Related Questions