Data Platform Developer Center >
Data Platform Development Forums
>
ADO.NET Entity Framework and LINQ to Entities
>
Entities and JSON serialization
Entities and JSON serialization
- Hi guys,
I'm trying to figure out the best way to use entities with JSON serialization. I have a WCF web service that I wan't to be able to accept an entity as a parameter. However becasue the entities have the DataContact attributes IsReference property set to true the entity cannot be serialized into JSON. Is there anyway to make an entity JSON serializable?
My current solution to the problem is creating other classes that represent the entities, and then transferring the property values over to the actual entities.
For example, I have a Claimant entity and an SClaimant class with the same properties as the Claimant entity. Here is the service method that implements this:
This solution is working but isn't ideal. Is it possible to make an entity JSON serializable? And if not is it possible to have an entity implement a custom interface so that the entity object and the serializable object both inherit the same interface?public long AddClaimant(SClaimant claimant) { Claimant claimantEntity = new Claimant(); claimantEntity.FirstName = claimant.FirstName; claimantEntity.MiddleInitial = claimant.MiddleInitial; claimantEntity.LastName = claimant.LastName; claimantEntity.Address = claimant.Address; claimantEntity.Province = int.Parse(claimant.Province); claimantEntity.City = claimant.City; claimantEntity.PostalCode = claimant.PostalCode; claimantEntity.HomePhone = claimant.HomePhone; claimantEntity.Mobile = claimant.Mobile; claimantEntity.Email = claimant.Email; Claimant addedClaimant = ClaimantManager.AddClaimant(claimantEntity); return addedClaimant.Id; }
If anyone has any insight into this I would greatly appreciate the help.
Thanks in advance,
Brian
Answers
- Read about EF & JSON here:
http://blogs.microsoft.co.il/blogs/idof/archive/2008/09/30/serializing-entity-framework-object-to-json.aspx
Please mark posts as answers/helpful if it answers your question- Marked As Answer byNoam Ben-Ami - MSFTMSFT, ModeratorMonday, November 09, 2009 6:14 PM
All Replies
- Read about EF & JSON here:
http://blogs.microsoft.co.il/blogs/idof/archive/2008/09/30/serializing-entity-framework-object-to-json.aspx
Please mark posts as answers/helpful if it answers your question- Marked As Answer byNoam Ben-Ami - MSFTMSFT, ModeratorMonday, November 09, 2009 6:14 PM


