Search code examples
c#ormdapperpetapocomassive

Best strategies when working with micro ORM?


I started using PetaPOCO and Dapper and they both have their own limitations. But on the contrary, they are so lightning fast than Entity Framework that I tend to let go the limitations of it.

My question is: Is there any ORM which lets us define one-to-many, many-to-one and many-to-many relationships concretely? Both Dapper.Net and PetaPOCO they kind of implement hack-ish way to fake these relationship and moreover they don't even scale very well when you may have 5-6 joins. If there isn't a single micro ORM that can let us deal with it, then my 2nd question is should I let go the fact that these micro ORMs aren't that good in defining relationships and create a new POCO entity for every single type of query that I would be executing that includes these types of multi joins? Can this scale well?

I hope I am clear with my question. If not, let me know.


Solution

  • I generally follow these steps.

    1. I create my viewmodel in such a way that represents the exact data and format I want to display in a view.
    2. I query straight from the database via PetaPoco on to my view models.

    In my branch I have a

    T SingleInto<T>(T instance, string sql, params object[] args);

    method which takes an existing object and can map columns directly on to it matched by name. This works brilliantly for this scenario.

    My branch can be found here if needed. https://github.com/schotime/petapoco/