I posted this to the WCF Data Service forum, but thought I would try here too since I'm using xamgrid.
I'm using silverlight to display objects retrieved from a WCF Data Service in a datagrid (i.e. the datagrid is being bound to a DataServiceCollection<GponOnt>). My GponOnt object has a navigation property called GponOntLocations that contains all the locations the GponOnt serves. I can of course bind directly to GponOntLocations and use a value converter to convert the collection of GponOntLocation objects to a string for display but in order to use all the filtering/grouping provided natively by the grid, it would be better if I bound the column to a simple "string" type instead of the collection. Given that, I thought I would just use partial classes on the client side like:
public partial class SrvStreetLocation { public override string ToString() { string addr = this.HouseNumber.Trim(); if (AdrStreet != null) { addr = (addr + " " + this.AdrStreet.PreDirectional).Trim(); addr = (addr + " " + this.AdrStreet.Street).Trim(); addr = (addr + " " + this.AdrStreet.StreetSuffix).Trim(); } addr = (addr + " " + this.Apartment).Trim(); return addr; } } public partial class GponOnt { public string Locations { get { if (GponOntLocations != null) { return string.Join(",", (from l in GponOntLocations select l.SrvLocation.SrvStreetLocation.ToString()).ToArray()); } else { return ""; } } } }
This works great, but when I go to perform CRUD operations on the GponOnt objects and post them back to the server with SaveChanges, I of course get an error saying "property name 'Locations' is not valid. I thought, simple , I'll just add a [NonMapped] or [NotSerialized] attribute to the above code but alas, I find the Silverlight version of the library doesn't support those. Anyone know of an easy solution to make this synthetic property I've created not be serialized or an equivalent workaround?
Someone was kind enough to suggest a solution over at:
http://social.msdn.microsoft.com/Forums/en/adodotnetdataservices/thread/fed23cd7-5b97-4ec0-b72d-3c7b3f32bf5d