EF dynamic proxies issues when Azure Appfabric Cache service is used as session state provider

We are trying to migrate our on-premise SAAS applicaiton to windows azure, and we have used lot of Entity Framework for a module specifically. As a migration part we are trying to migrate and test the application in phases. We are trying to using Azure appfabric cache service as a session state provider.

When I try to configure the session state to appfabric cache we are running in to these issues related to Entity framework, pls see error no 2. First we got this error no 1. to fix this issue we have the class as [DataContract] and the issue is resolved.

error no 1. System.Runtime.Serialization.InvalidDataContractException: Type 'XX.XX.XXX' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.

error no 2. The property 'AdXXXXXX' on type 'CaXXXXX_9FDDBE5B2C99F9C5DE2E0DCD2E8CC77D2CB59220D1A3413E91AF5A2B6A23026D' cannot be set because the collection is already set to an EntityCollection.

We are completely lost of how to fix these issues, and when googled a couple of threads tells we need to remove the virtual access modifier for the properties. But the same code works with out any issues like this on-premise, and the code is generated automatically by the EF on each update of the model. We are also have other option of going to SQLAzure as session state provider in the second chance, but we are hoping there are also the same problems may exists as the data need to be serialized when stored in the session.

http://social.msdn.microsoft.com/forums/en/adonetefx/thread/99d8d4a1-5ab1-42dc-b9db-5087be02162d http://blog.iannelson.systems/entity-framework-week-part-3-runtime-issues-encountered/

We are not using lazy loading and the classes are generated by EF automatically when we update the model from the database.

Answers


Could you try removing the virtual keyword from all properties except the ones you use for lazy loading / navigation properties (ie: remove it from all native types)?

Reference: Code First adding to collections? How to use Code First with repositories?


Need Your Help

How do I get nth number of records from 100 records by select query in SQL Server?

sql sql-server sql-server-2008

I want to select nth record randomly from 100 of records by using select query in SQL Server

Limit Shape's Border with CSS

html css css-shapes

I need to achieve an effect like in this demo.