public CategoryViewModel GetCategoryById(int categoryId) { try { CategoryDC categoryDC = CategoryServiceClient.GetCategoryById(categoryId); return(new CategoryViewModel { Id = categoryDC.Id, CategoryName = categoryDC.CategoryName }); } catch (FaultException ex) { throw new ApplicationException(ex.Message); } }
public JsonResult ExplicitlyLoadingForManyEntities() { var context = new OrdersContext(); var category = context.Categories.Find(1); context.Entry(category).Collection(c => c.Products).Load(); var categoryDC = new CategoryDC { CategoryId = category.CategoryId, CategoryName = category.CategoryName, Products = category.Products.Select(p => new ProductDC { ProductId = p.ProductId, ProductName = p.ProductName }) }; return(Json(categoryDC, JsonRequestBehavior.AllowGet)); }