New Posts New Posts RSS Feed: Restore Cache bug
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Restore Cache bug

 Post Reply Post Reply
Author
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Topic: Restore Cache bug
    Posted: 14-Dec-2010 at 10:34am
Hi,

DevForce fails to restore an entity set restored into Silverlight from a desktop model containing an IdGenerator.

Additional information: Element 'http://ideablade.com/EntityModel:NextIdGenerator' contains data of the 'http://schemas.datacontract.org/2004/07/Northwind.Model:NumericIdGenerator' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'NumericIdGenerator' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.


The solution to this is to create a dummy generator in Silverlight:

    [DataContract]
    public class NumericIdGenerator1 : IIdGenerator
    {
        public bool IsApplicable(IDataSourceKey dataSourceKey)
        {
            return false;
        }

        public object GetNextTempId(DataEntityProperty property)
        {
            return null;
        }

        public bool IsTempId(UniqueId uniqueId)
        {
            return false;
        }

        public void Reset()
        {
            return;
        }

        public UniqueIdMap GetRealIdMap(UniqueIdCollection tempIds, IDataSourceKey dataSourceKey)
        {
            return null;
        }

        public UniqueIdCollection TempIds
        {
            get { return null; }
        }
    }
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 14-Dec-2010 at 7:31pm
Thanks for describing the problem and your workaround.   The problem occurs because the EntityCacheState is serialized and deserialized using the DataContractSerializer, which is very strict about type definitions and "known" types.  The ECS is essentially a serializable list of entities and some state, including any temporary IDs.  Because the ECS has special handling for temporary IDs it also includes the IdGenerator in its serialized state.   You can see this if you save the ECS in text format - there's more there than just simple entity definitions.
 
We may look into some sort of lightweight ECS for those use cases when an IdGenerator isn't ever wanted, but for now this is more of a known, and sometimes irritating, situation and not a bug we can easily fix.  If you only need serialized entities, and can attach or add them to an EM manually, then you can also serialize a List<Entity> using the SerializationFns, and not go through the CacheStateManager/EntityCacheState.
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 14-Dec-2010 at 9:34pm
Thanks for the response, Kim. The workaround seems to work well enough, so it's not a big deal. 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down