Login | Register  
Latest 20 PostsMinimize
04 Sep 2010 05:25 PM
28 Aug 2010 08:51 PM
RE: MONO - Fastalanasa
28 Aug 2010 01:51 AM
RE: MONO - Taliesen
28 Aug 2010 01:31 AM
RE: MONO - Fastalanasa
27 Aug 2010 04:10 PM
RE: MONO - Taliesen
27 Aug 2010 03:16 PM
RE: MONO - Fastalanasa
27 Aug 2010 09:26 AM
RE: MONO - Karak
27 Aug 2010 05:04 AM
RE: MONO - Taliesen
25 Aug 2010 04:00 PM
RE: MONO - Fastalanasa
25 Aug 2010 04:49 AM
RE: MONO - Taliesen
23 Aug 2010 04:19 AM
RE: MONO - Fastalanasa
23 Aug 2010 02:57 AM
23 Aug 2010 02:54 AM
RE: MONO - Taliesen
23 Aug 2010 02:52 AM
RE: MONO - Fastalanasa
23 Aug 2010 02:36 AM
RE: MONO - Fastalanasa
23 Aug 2010 02:13 AM
RE: Stat System - Fastalanasa
23 Aug 2010 01:57 AM
23 Aug 2010 01:34 AM
23 Aug 2010 01:32 AM
23 Aug 2010 01:30 AM
ForumsMinimize
Code Layout question
Last Post 15 Nov 2009 07:32 PM byFastalanasa. 4 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
AuthorMessages
FastalanasaUser is Offline
Grumpy Half-Elf
Advanced Member
Advanced Member
Send Private Message
Posts:705
Avatar

--
27 Jun 2009 06:16 PM  

I got a set of T4 templates to create domain objects from each table in whatever database I point it to. I tested this with SQL Server and SQLite. Let me put some screenshots, before I ask my questions.

EntityCreator.tt is the main template. You only set some properties and run this template as a "Run Custom Tool". Then you get all the classes generated for you.

This is what the generated classes look like inside. As you can see, I'm generating them as partial classes.

I created this set of templates, so that I wouldn't have to code this by hand. I don't want to spend my time doing tedious stuff by hand, when it can be generated. The other reason is that this will facilitate using NHibernate. We can put the actual class logic on a different file. We could name them something like ClassName.Logic.cs. So ANSI.cs, would have a counterpart of ANSI.Logic.cs.

I know that we have a lot of these domain type classes all over our framework. I used WheelMUD.DomainObjects for a lack of a better name. So here are my questions:

Would it be feasable for us to put all the "domain" classes in one namespace?

Would we then just keep the current layout and rename the current classes as ClassName.Logic.cs?



FastalanasaUser is Offline
Grumpy Half-Elf
Advanced Member
Advanced Member
Send Private Message
Posts:705
Avatar

--
28 Jun 2009 12:48 AM  

Alright, now I got the NHibernate mapping classes being generated from a T4 template.



FastalanasaUser is Offline
Grumpy Half-Elf
Advanced Member
Advanced Member
Send Private Message
Posts:705
Avatar

--
28 Jun 2009 04:36 PM  

Here's a project with all the T4 codegen stuff I've done so far. This now contains the following:

  • DataTransferObjectCreator.tt
  • DomainObjectCreator.tt
  • MappingCreator.tt

The connection string is in App.config and it is pointing to the current SQLite database. To change it to SQL Server just edit the connection string in App.config. Make sure to change the "providerName" and "connectionString" to their appropriate values. As of now, these templates also support SQL Server CE, MySQL, OleDb, and PostGres databases.

I'm hoping to create 2 more templates, one to do a mapping between domain objects and data transfer objects, and the other to do conversions from data transfer objects and Json structures.

All of these things are very tedious to do by hand. I want to avoid this tiresome task, and allow us to concentrate on the "fun" stuff. Now we just need to figure how how to lay all of this out.

 


WheelMUDCodeGen.zip
WheelMUDCodeGen.zip
WheelMUDCodeGen.zip
WheelMUDCodeGen.zip

scionwestUser is Offline
New Member
New Member
Send Private Message
Posts:8

--
15 Nov 2009 05:41 PM  

I'm confused why you are using partial classes like that instead of using inheritance? Is it a requirement of the T4 templates?



Developer of Managed Scripting | .NET Script Engine
Developer of iRingtones | Free ringtone conversion tool for iPhone
Scionwest Blogging
Scionwest Twitter
FastalanasaUser is Offline
Grumpy Half-Elf
Advanced Member
Advanced Member
Send Private Message
Posts:705
Avatar

--
15 Nov 2009 07:32 PM  
Posted By scionwest on 11/15/2009 10:41 AM

I'm confused why you are using partial classes like that instead of using inheritance? Is it a requirement of the T4 templates?

Half of it has to do with how NHibernate works and is laid out. The other half is because the templates needed to be run every time there are changes in the database. Partial classes permits us to have custom code that will not get overwritten whenever the templates get run. That's what the ClassName.NoGen.cs files are.



You are not authorized to post a reply.

Active Forums 4.2
Copyright 2007-2010 by WheelMUD  | Terms Of Use | Privacy Statement
Google Analytics Alternative