REST with WCF and Entity Framework with JSON Serialization






4.67/5 (4 votes)
This is an alternative for "REST with WCF and Entity Framework with JSON Serialization"
Note : This is an alternate solution for This Article.
Alternate Solution for JSON Serialization
You can use Json.NET library to serialize Entity FrameWork object. It is fast and more effective then given solution. JavascriptSerialization but it is taking more time then Json.NET.
You can find source code from : http://json.codeplex.com/
Simple Example
using (FrameworkContainer fc = new FrameworkContainer()) //Entity Framework Object
{
var realObject = fc.GetAccountInformation("AmitGajjar"); // Calling Entity Framework Function (SP)
using (MemoryStream ms = new MemoryStream())
{
var result = from account in realObject
select new
{
Name = account.Account_Name,
City = account.Address1_City,
Phone = account.Address1_Telephone
};
// serializedObject will be json object from entity
var serializedObject = JsonConvert.SerializeObject(result);
}
}
Hope this will help you to implement serialization very quickly.