0

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 https://blog.iannelson.uk/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.

Ian Nelson
  • 57,123
  • 20
  • 76
  • 103
CSKR
  • 101
  • 1
  • 8

1 Answers1

0

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?

Community
  • 1
  • 1
Sandrino Di Mattia
  • 24,739
  • 2
  • 60
  • 65
  • We are not using lazy loading and the classes are generated by EF automatically when we update the model from the database. We dont have any control on the classess generated by EF. or do we need to remove the virtual for properties manually. – CSKR Apr 13 '12 at 11:03
  • No, I wouldn't remove the virtual keyword manually. Could you try to turn off change tracking: context.SomeTable.MergeOption = MergeOption.NoTracking; – Sandrino Di Mattia Apr 13 '12 at 11:14
  • Where can we add the option MergeOption.NoTracking on tables, Basically we tried by adding on the propeties, but still getting the same problem. – CSKR Apr 16 '12 at 06:12
  • We are able to some how resolve the above problem by adding DataContract and DataMembers to the members of the autogenerated class with out removing virtual keyword, but still could not find the complete solution to store the entity objects in Azure Appfabric using sesion state. We are getting an error Type 'System.Collections.Generic.ICollection`1[SB.Mpm.Entity.Client]' cannot be serialized when a method is return the collection. – CSKR Apr 16 '12 at 17:39