Where are micro orm tools positioned in the application architecture

432 views Asked by At

Simple statements like this: "Select x,y,z From Customer" are in the Data Access Layer.

If there would be logic in the query like filtering for customers from a certain city I would have to put the filtering in my business layer and do it on the in-memory customer collection.

When I regard now the Micro ORM tools they often show Sql statements with logic like:

var a = db.SingleOrDefault<Product>("SELECT * FROM SalesLT.Product WHERE ProductID = @0, 123);

Where should I put now this line of code? In the Business Layer or the Data Access Layer?

There is logic inside the statement which should belong in Business Layer. But then I have

Select statements inside my BLL ??

This is all confusing.

2

There are 2 answers

1
Peter Ritchie On

If you want a 3 layer model, then use of either the db context or the micro orm need to be done on the data access layer.

0
Yogiraj On

In my opinion,it is personal preference. I like the SQLs close to the method that is using them unless there is need to have them shared between different BLL classes. It makes the change easier. For simple operations, you can use extension methods like Dapper.Simple Crud, so that you dont have write same operations over and over again. You can take a look at my github repo for implementation. I put it together for my talk on Micro-ORMs. The solution has sample usage for Massive, Dapper, PetaPoco, and Simple.Data. Here's a link to a one of the service classes, so that you don't have to dig through too much. If you have any suggestions, please let me know or even better send me a pull request. :)