Thursday, 11 February 2016

ORM in C#

ORM, stands for Object Relation Mapping is a way to map your relational database to logical objects in the programming language which comes to an advantage to reduce the lines of code to implement a business process and provides some sort of persistency to the objects.

Based on abstraction, ORM manages the mapping details between a set of objects and underlying relational databases, XML repositories or other data sources and sinks, while simultaneously hiding the often changing details of related interfaces from developers and the code they create.

Types of ORMs available: (From Wiki)

  1. Base One Foundation Component Library, free or commercial 
  2. Castle ActiveRecord, ActiveRecord for .NET, open source 
  3. DatabaseObjects .NET, open source 
  4. DataObjects.NET, commercial 
  5. Dapper, open source 
  6. ECO, commercial but free use for up to 12 classes 
  7. Entity Framework, included in .NET Framework 3.5 SP1 and above 
  8. EntitySpaces, was commercial, now free 
  9. iBATIS, free open source, maintained by ASF but now inactive. 
  10. LINQ to SQL, included in .NET Framework 3.5 
  11. Neo, open source but now inactive. 
  12. NHibernate, open source 
  13. nHydrate, open source 
  14. Persistor.NET, free or commercial 
  15. Quick Objects, free or commercial 
  16. SubSonic, open source but now inactive 
  17. XPO, commercial 

ORM hides and encapsulates change in the data source itself, so that when data sources or their APIs change, only ORM needs to change to keep up—not the applications that use ORM to insulate themselves from this kind of effort. 

This capacity lets developers take advantage of new classes as they become available and also makes it easy to extend ORM-based applications. In many cases, ORM changes can incorporate new technology and capability without requiring changes to the code for related applications. 

Which ORM you should use depends on the answers of below questions, as yourself before going to use any of ORM,

  1. What database providers you want the ORM to support ? SQL Server,MySQL, Oracle, etc.
  2. Do you need model-first or db-first support ?
  3. What is my performance criteria [memory, processing] ?
  4. Are you going to use it in web-app or a desktop-app ?
  5. Do you have distributed clients in your application ?

NHibernate is more mature, feature rich, with a more advanced community and not likely to be discontinued when MS decides to break compatibility again. Entity Framework is more mainstream and is supported out-of-the-box. You will find more beginner books for EF, more advanced books for NH.

I will explain majorly used ORMs in my next posts. be in touch.. :)

Thanks for reading.....