zain85 / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Managing Dapper scripts #33

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Not sure whether I should post here or on SO. Really its just a general 
question at you guys how you manage your Dapper scripts.

I've taken to exposing my queries as properties on a static class. This makes 
it a bit easier when I need to tweak the query as there's no noise from other 
code - see http://codepaste.net/tfb8so

Within my service layer I can then just call:

cn.Query<PostModel>(BlogQueries.PublicPostsQuery, new { .... } )

Notice that I'm also doing a bit of string concatenation to reduce repeating 
sql such as the fields to retrieve and the criteria needed twice (once for the 
count and once for the select).

Do you guys do something similar or have any other tips?

Original issue reported on code.google.com by b...@planetcloud.co.uk on 4 Jun 2011 at 1:50

GoogleCodeExporter commented 8 years ago
Personally I like keeping the script very close to the C# - very often directly 
inline to Query, or at worst a few lines away. That way I can see immediately 
what is going on in a query, and how I might tweak it.

The re-use between queries is small, so I see no benefit in moving them 
somewhere central.

But that's just me.

If you support multiple DB then the scenario may be more complex, of course.

Original comment by marc.gravell on 4 Jun 2011 at 3:15

GoogleCodeExporter commented 8 years ago

Original comment by marc.gravell on 9 Jun 2011 at 6:24