3

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?

Kamarey
  • 10,832
  • 7
  • 57
  • 70
  • Ah - missed that bit about it working in some circumstances. – ChrisF Jun 03 '11 at 16:30
  • 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. – Akash Kava Jun 04 '11 at 06:43
  • @Akash Kava: Looks like you are right about RIA and multiple domain service files. If I create a single domain service for all entities - it works. So please make your comment as an answer - I will accept it. Thanks. – Kamarey Jun 04 '11 at 12:38

4 Answers4

2

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.

Akash Kava
  • 39,066
  • 20
  • 121
  • 167
0

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));
}
grimus
  • 3,175
  • 2
  • 18
  • 26
0

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.

Community
  • 1
  • 1
BentOnCoding
  • 27,307
  • 14
  • 64
  • 92
  • I saw this question before and didn't find it helpful. My CustomerService already has customer CUD methods with related attributes. Or I missing something? – Kamarey Jun 03 '11 at 19:13
  • No, I still don't call Update as I crashed while setting product's property: customer.Products.First().Description = "something"; Calling Update will be the next problem. – Kamarey Jun 03 '11 at 19:35
  • I added a different suggestion to my anwser please try it because it sounds like you are doing everything correctly but its hard to verify. – BentOnCoding Jun 03 '11 at 19:48
  • I used this wizard when created my domain services (including 'Enable Editing' checkbox). – Kamarey Jun 03 '11 at 20:04
0

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");
JBrooks
  • 9,901
  • 2
  • 28
  • 32