EFJson Documentation

The EFJson will serialize just the primitives properties of the Entity Framework, this way the relationship will serialize just if you indicate it using the paths parameter.

To make a simple copy of Entity Framework entity, the EFJson uses the System.Emit to generate the new class.

Below some code snippets, you can download the source code with the full example.

Returning One Table Data

 

            using (NorthwindEntities entities = new NorthwindEntities())
            {
                var query = entities.Categories.OrderBy(c => c.CategoryName).Take(20).ToList();
                var jsonObjects = query.Select(c => JsonHelper.ConvertToSimpleObject(c));
                return Json(jsonObjects, JsonRequestBehavior.AllowGet);
            }


 

 

Returning One Relationship Data

 

            using (NorthwindEntities entities = new NorthwindEntities())
            {
                var query = entities.Products.Include("Categories").OrderBy(c => c.ProductName).Take(20).ToList();
                var jsonObjects = query.Select(c => JsonHelper.ConvertToSimpleObject(c, "Categories"));
                return Json(jsonObjects, JsonRequestBehavior.AllowGet);
            }


 

Returning Many Relationship Data

            using (NorthwindEntities entities = new NorthwindEntities())
            {
                var query = entities.Suppliers.Include("Products").OrderBy(c => c.CompanyName).Take(4).ToList();
                var jsonObjects = query.Select(c => JsonHelper.ConvertToSimpleObject(c, "Products"));
                return Json(jsonObjects, JsonRequestBehavior.AllowGet);
            }

Returning Multiple Paths Data

            using (NorthwindEntities entities = new NorthwindEntities())
            {
                var query = entities.Suppliers.Include("Products.Categories").OrderBy(c => c.CompanyName).Take(4).ToList();
                var jsonObjects = query.Select(c => JsonHelper.ConvertToSimpleObject(c, "Products.Categories"));
                return Json(jsonObjects, JsonRequestBehavior.AllowGet);
            }


Last edited Oct 19, 2012 at 12:23 AM by MAGomes, version 4

Comments

No comments yet.