1

I'm working with NHibernate. I need to generate DTOs to carry data around. I don't want to do it by hand. Hence I'm looking for shortcuts and tools to help me. I was hoping to find a simple tool that generates a objects which mirror the database tables. The properties of these objects would have same name and equivalent types as of database tables.

dev.e.loper
  • 35,446
  • 76
  • 161
  • 247
  • @MichaelMaddox I looked at T4 but couldn't find exactly how to do it. Is there an example of how to use T4 to do what I'm trying to do? – dev.e.loper Oct 26 '11 at 11:09
  • not a perfect example, but you can get the idea here: http://stackoverflow.com/questions/2223421/t4-template-to-create-multiple-html-for-example-output-files-per-table-from/3070406#3070406 – Michael Maddox Oct 28 '11 at 10:10

3 Answers3

0

A tool that looks at your database and creates types is called an ORM (Object Relational Mapper). There are both free and commercial ones available: Entity Framework and LLBLGEN spring to mind.

If you already have your types, you could use AutoMapper to convert to DTOs:

AutoMapper is an object-object mapper. Object-object mapping works by transforming an input object of one type into an output object of a different type. What makes AutoMapper interesting is that it provides some interesting conventions to take the dirty work out of figuring out how to map type A to type B. As long as type B follows AutoMapper's established convention, almost zero configuration is needed to map two types.

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
0

Visual Nhibernate can generate domain objects from your database schema. You could then modify these objects and end up with the DTOs you need. Once you have both object types you can follow Mitch's advice and use a tool like EmitMapper or AutoMapper to automatically map Domain objects to DTOS.

Newbie
  • 7,031
  • 9
  • 60
  • 85
0

Found what I was looking for while watching one of the sessions of http://summerofnhibernate.com/ specifically Session 08: Effective Techniques for Database-Driven Modeling.

The tool he is using is called MyGeneration which builds DTOs by looking at database tables.

dev.e.loper
  • 35,446
  • 76
  • 161
  • 247