locked
Adding custom properties to an IsolatedStorageOfflineEntity RRS feed

  • Question

  • It appears that I can not add custom properties to an IsolatedStorageOfflineEntity i.e.

     

     

     public partial class orders
     {
      public IList<order_details> OrderDetails { get; set; }
      }
    

     

    If I do I get an error when sync'ing. Am I correct in this observation and what is the best practice to work around this limitation?

     

     


    Tuesday, June 28, 2011 5:47 PM

Answers

  • What is the error you get when you sync?

    Yes I think currently the OfflineEntities are bound to the schema of the table you provision. The deserialization and serialization code reflects through all properties of the entity. When we release the source code of the project, you can change it to only read/write properties with a specific attribute and ignore other properties.

    • Marked as answer by GAX user Friday, July 1, 2011 3:07 PM
    Friday, July 1, 2011 12:44 AM

All replies

  • What is the error you get when you sync?

    Yes I think currently the OfflineEntities are bound to the schema of the table you provision. The deserialization and serialization code reflects through all properties of the entity. When we release the source code of the project, you can change it to only read/write properties with a specific attribute and ignore other properties.

    • Marked as answer by GAX user Friday, July 1, 2011 3:07 PM
    Friday, July 1, 2011 12:44 AM
  • Thanks for your reply. 

    The error message I get is "TypeCode Object is not a supported type."

    I suppose asking when the source code will be released is getting rather redundant? 

    Friday, July 1, 2011 3:07 PM
  • I was having the same issue and the source code is now available. After a couple of hours of trying to understand the code (and learning how to use attributes), I made the following changes and it works. In case anyone comes up against the same issue, I'm putting the code I used here. It might not be the best, and I haven't done any rigorous testing to make sure it won't fail, but for now it seems to be fine:

    I first created a class to be used as the attribute:

    [AttributeUsage(AttributeTargets.Property)]
    public class NonSerializedAttribute : Attribute { }

    I added a check to make sure it was NonSerialized in Line 55 of ReflectionUtility.cs

    props = props.Where((e) => 
                                (!e.Name.Equals("ServiceMetadata", StringComparison.Ordinal) && 
                                e.GetCustomAttributes(typeof(NonSerializedAttribute), false).Length == 0 &&
                                e.GetGetMethod() != null && 
                                e.GetSetMethod() != null && 
                                e.DeclaringType.Equals(type))).ToArray();

    Now, when I add a property to the partial class, I do the following:

    public partial class Items { 
        [NonSerialized] 
        public Person Owner {get; set;} 
    }

    I'll update this if I come against any issues. Hopefully this is useful for someone!

    Friday, May 4, 2012 11:43 PM
  • ... I made the following changes and it works. In case anyone comes up against the same issue, I'm putting the code I used here. ... Hopefully this is useful for someone!

    Thank you very much for sharing your code! Someone definatly should put a copy of SyncFramework on CodePlex or something so we can share and collect patches in a much more professional way.

    Senior Jack of all trades

    Tuesday, May 8, 2012 1:38 PM