Tuesday, September 3, 2013

Some note about Linq, WCF, EntityFramework, WebApi, oData

The key to understand the syntax of linq, is it is built based on IEnumerable, so everything is based on a single element from the IEnumerable collection, if you see a variable declaration coming out of nowhere, then you can think of it as a instance of a IEnumerable instance. This is particular useful to understand Lambda syntax

WCF provides an easy way to implemenat oData service, but it is used mainly for .net client. If you create a oData service to support ios, Android devices, then it is better to create the oData service with WebApi, developer has better control over web API then WCF's customization.

EntityFramework helps to expose the backend data as objects, but when using WebApi, it is not very stable to serialize the dependent objects included in the foreign key field, the easy solution is just returning the foreign key field as a simple field data instead of returning it as a child  object. As for mobile client, it is not proper to return all objects included in object mapping, if client needs dependent objects, it is better to let client send another separate request.

When using EntitySetController to build oData endpoint, be sure the controller name matches the entity name, otherwise the resource cannot be found:

  private static IEdmModel GetImplicitEDM()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Customer>("Customers");
            builder.EntitySet<Order>("Orders");
            builder.EntitySet<Order_Detail>("OrderDetails");
            return builder.GetEdmModel();
        }

public class CustomersController : EntitySetController<Customer, string>
   

No comments:

Post a Comment