4

I have written a wrapper around ADO.NET's DbProviderFactory that I use extensively throughout my applications. I also have written a lot of code that maps IDataReader rows to POCOs. However, as I have tons of classes the whole thing is getting to be a pain in the ass to maintain.

I have been looking at replacing the whole she-bang with a micro-orm like Petapoco. I have a few queries though:

  1. I have lots of POCOs that contain other POCOs in them as properties. How well does the Petapoco support this?
  2. Should I use a ORM like Massive or Simple.Data that returns a dynamic object and map that to a POCO?
  3. Are there any approaches I can take to the whole mapping of rows to POCOs? I can't really use convention-based tools as my database isn't particularly consistent in how it is designed.
Amit Joshi
  • 15,448
  • 21
  • 77
  • 141
ScottD
  • 173
  • 5
  • 15
  • By the way, I am not that interested in going down the full-blown ORM route. – ScottD Jul 25 '12 at 20:07
  • Dapper supports nested mappings with ease (As can PetaPoco, judging by the documentation). To 3) - as long as the returned columns match a property, Dapper can map it. So you wouldn't have to change your DB design, just the queries if there's a property-column mismatch. – Alex Jul 26 '12 at 09:01
  • For the "convention" issue, it is likely that I'm going to add support for the unconventional; see http://stackoverflow.com/questions/11703600/dapper-column-number-rather-than-column-name – Marc Gravell Jul 28 '12 at 20:05

3 Answers3

0

How about using a text templating/code generator to build out a lightweight persistence layer? I have a battle-hardened open source project called TextMetal to generate the necessary persistence layer based on tried and true architectural decisions. The only lacking thing is object to object relations but it does support query expressions and works well with poorly designed data schemas.

You can see a real world project that uses the above tool call Can Do It For.

Feel free to ask me about any design decisions once you take a look-sse.

0

Simple.Data automagically casts its dynamic type to static types. It will map nested properties as long as they have been eager-loaded using the .With method. So for example

Customer customer = db.Customer.WithOrders().Get(42);

would populate the Orders property of the customer object.

Mark Rendle
  • 9,274
  • 1
  • 32
  • 58
0

Could you use QueryFirst, or modify it? It takes your sql and wraps it in vanilla ADO code, generated at design time. You get fresh POCOs from your result schema every time you save your file. Additionally, you can choose to test all queries and regenerate all wrappers via the option in the tools menu. It's dependent on Sql Server and SqlClient, so unless you do some modification, you'll lose DbProviderFactory.

bbsimonbb
  • 27,056
  • 15
  • 80
  • 110