locked
Extending entities RRS feed

  • Question

  • Hi

    I'm working on a Silverlight business app using RIA services. For the DALC I'm using LINQ to SQL.

    I was under the impression that I could add properties to my entities. Let's say my entity is a Screen, and it has properties for height and width. I want to include a property for total pixels, which is height * width.

    So, on the server side, I create a partial class for Screen and add my new property, with only a Get accessor. I see in the generated code that my property is persisted onto the client and it even marks it read-only for me. All good so far.

    Next I databind to a grid. Height, Width and Total Pixels are all displayed. *However* the problem comes when I want to make changes - of course I can't (and don't want to) change Total Pixels. But if I make a change to height or width, and save; the change is not persisted. No exceptions are thrown, but when I refresh the page the old value is back.

    I'm sure this relates to the new property I added - if I comment that out, I can update the height and width and the changes get persisted to the DB. Put my property back in and it breaks again.

    Note that I also tried marking the property '.shared.cs' (is this necessary though?).

    Have I misunderstood what I can do in terms of extending my entities?

    Thanks in advance,

    Richard
    Tuesday, August 18, 2009 6:59 PM

Answers

  • Yes, you need to put the .shared.cs on the file with the property, otherwise the calculated version of the property will not transfer. You are hitting a bug in the current release which will be fixed as soon as the version of RIA Services that sits on top of ADO.NET Data Services gets released. To get around the bug, go into the metadata file, add a line in it for your calculated property and put an [Exclude] attribute on it.

    Tuesday, August 18, 2009 7:24 PM

All replies

  • Yes, you need to put the .shared.cs on the file with the property, otherwise the calculated version of the property will not transfer. You are hitting a bug in the current release which will be fixed as soon as the version of RIA Services that sits on top of ADO.NET Data Services gets released. To get around the bug, go into the metadata file, add a line in it for your calculated property and put an [Exclude] attribute on it.

    Tuesday, August 18, 2009 7:24 PM
  • Hi Colin

    I just tried this and it works great.

    Thanks for your help.

    Richard

    Wednesday, August 19, 2009 8:18 AM
  • As a follow up question: is there any way I can still decorate my custom property with meta data?

    Annotations in the metadata class are ignored (presumably because of the 'exclude'). When I make annotations directly on the property in the partial class, it breaks the data binding again...

    Thanks in advance,

    Richard

    Wednesday, August 19, 2009 10:56 AM
  • I do not know the answer to that one, but I am going to guess no. This of course will change as soon as the underlying problem goes away.

    Wednesday, August 19, 2009 11:20 AM
  • Thanks for your help.

    Richard

    Wednesday, August 19, 2009 1:09 PM