开发者

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?


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.


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


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.


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜