Click here to Skip to main content
15,884,995 members
Articles / Programming Languages / C#
Alternative
Article

REST with WCF and Entity Framework with JSON Serialization

Rate me:
Please Sign up or sign in to vote.
4.67/5 (4 votes)
1 May 2013CPOL 15.3K   10  
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  

C#
 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.  

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --