Print Page | Close Window

Restore Cache bug

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2373
Printed Date: 15-Apr-2025 at 1:11pm


Topic: Restore Cache bug
Posted By: smi-mark
Subject: Restore Cache bug
Date 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; }
        }
    }



Replies:
Posted By: kimj
Date 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.


Posted By: smi-mark
Date 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. 



Print Page | Close Window