Sunday, December 15, 2013

IQueryable drawbacks (Repository pattern, OData)


Developers, developers, developers have new crazy idea "to publish data in IQueryable interface".

I For example, to provide IQueryable with WCF Data Service

public class MyWcfDataService : DataService<MyEfModel>
{
   [WebGet(ResponseFormat = WebMessageFormat.Json)]
   public IQueryable<GetMyListEF> GetMyList()
   {
       using (MyEfModel context = this.CurrentDataSource)
       {
           return context.GetMyListEF().ToList().AsQueryable();
       }
   }
}
(example from one of the hundreds common posts in the internet)

At first, what if context.GetMyListEF() will return millions of rows? All of them will be send to the client. Is client expect such thing?

Second point will be a bad nature of the IQueryable in real life. Currently nobody can provide full implementation of this interface. Even Entity Framework with modern sql providers does not have ideal implementation of the interface. There lots of exceptions of impossibility to convert to T-SQL code. Or with success we have bad performance (the reason stackoverflow.com choose Micro ORM dapper).

If some provide IQueryable<T> interface then clients expect full implementation of it. Not partial, FULL!


II Next example is widely using our lovely interface in Repository pattern, usually it looks like

public class MyRepository<T> : IRepository<T>
{
   public IQueryable<T> GetModels()
   {
       // implementation
   }
}

- What is the purpose of abstracting Repository?
- To make it possible exchange in future with another implementation
- Can you make NoSql storage or File storage using in future instead of MS SQL?
- No! Querable providers are very complex to create for such storages.


III Same problem with OData, that is pushing by Microsoft.
With OData users can query data by passing parameters in URI, for example,
http://services.odata.org/OData/OData.svc/Category(1)/Products?$top=2&$orderby=name

The idea is great, but, but, but
"Users like cheating only if it is a focus!"

If you take Sharepoint services with OData you will find the same problem. The service just cannot provide all possible ways of using it. Users will be restricted to the platform in their heads, instead of be lucky with interface features.


P.S. Better use what users expect to get from your services (IEnumerable<T> in most cases).

Resources:
IQueryable is Tight Coupling by Mark Seemann

3 comments:

  1. Our company has well equipped machines and modern tools that ensure quality and fast production with the help of which we are able to manufacture more than 5,000 office chairs per year. And thus, we are able to meet the ever- growing demand of chairs. Among the many places where our products are supplied among those two biggest supplies are done in Mumbai, Pune in India.

    Please visit Our Sites:Chair Manufacturers in Mumbai
    Chair Supplier in Mumbai

    Chair Manufacturers in Mumbai
    Chair Supplier in Mumbai
    Office Chair Supplier in Mumbai
    Visitor Chair Supplier in Mumbai
    Chair Dealers in Mumbai
    Top Chair Manufacturers in Mumbai
    Best Chair Manufacturers in Mumbai

    ReplyDelete

  2. There are many packers and movers in Hyderabad who are looking for ways to make easy money from innocent families and individuals like you who are planning to relocate. Such packers and movers Hyd may either provide extremely bad service and end up damaging your goods permanently, or disappear with your entire household items instead of delivering them to the destination. Hence, the most crucial step before you hire any movers packers in Hyderabad is to verify their authenticity and check if they capable of providing good quality services.
    Packers and Movers in Hyderabad
    Packers and Movers in Jubilee Hills
    Packers and Movers in Banjara Hills
    Packers and Movers in Kondapur
    Packers and Movers in Madhapur
    Packers and Movers in Gachibowli
    Packers and Movers in Chanda Nagar

    ReplyDelete