domain driven design & code generation

5 views
Skip to first unread message

FlyAtDusk

unread,
Nov 26, 2009, 6:35:34 AM11/26/09
to S#arp Architecture
please bear with me on this, i'm still a newbie!

in my traditional 3-tier apps, i was accustomed to running a code
generator against an existing database and getting everything (all my
entities etc) from that as a starting point from the one click...sql
for stored procs, dal, bll and ui. therefore, i had to manually create
the d/base first and work up from there. this is/was no great deal
since sql server has a great interface for creating tables,
relationships etc.

with ddd, however, and using the t4 templates, i seem to need to first
create the entities, manually, one by one, by tweaking the template(s)
and after that, create the tables manually, one by one, then create
the stored procedures, etc. is this the case? seems like (relatively)
a lot of work. or is there something i'm missing?

please excuse if this is a silly question.

Alexis Kennedy

unread,
Nov 26, 2009, 7:12:19 AM11/26/09
to sharp-arc...@googlegroups.com
You can tell NHibernate to generate the DDL scripts for all mapped objects (especially easy if you're using automapping).

Because I'm a lazy, smelly coder working solo, I just use the code below, keeping the test commented out except when I need to update my SCC'd DDL script. This will write out the script to the console. .Create(false, true); will actually run it against your db.

I imagine the likes of Kyle have a more robust solution with build scripts and such. :)


    [TestFixture]
    [Category("DBTests")]
    public class MappingIntegrationTests
    {
        private Configuration configuration;

        [SetUp]
        public virtual void SetUp()
        {

            string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();
            configuration = NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies,
                                   new AutoPersistenceModelGenerator().Generate(),
                "../../../../app/Echo.Web/NHibernate.config");
        }

    // [Test]
        public virtual void BuildSchema()
        {

            new SchemaExport(configuration).Create(true, false);

        }
}

2009/11/26 FlyAtDusk <flya...@yahoo.co.uk>

--

You received this message because you are subscribed to the Google Groups "S#arp Architecture" group.
To post to this group, send email to sharp-arc...@googlegroups.com.
To unsubscribe from this group, send email to sharp-architect...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sharp-architecture?hl=en.





--
http://www.failbettergames.com

http://www.fallenlondon.com

Oleg Sych

unread,
Nov 26, 2009, 8:04:27 AM11/26/09
to S#arp Architecture
You can do DDD with LINQ to SQL (http://t4toolbox.codeplex.com). The
L2S designer in Visual Studio allows you to do DDD model-first and
strikes a good balance between relational, OO models and simplicity.
Unfortunately, it only allows you to create a single diagram per
model, which becomes difficult to use once you have more than 50
tables.

HTH,
Oleg

Kyle Baley

unread,
Nov 26, 2009, 9:10:23 AM11/26/09
to sharp-arc...@googlegroups.com
Yeah, I pretty much do the same thing. I think NHibernate also has a way of updating the schema (SchemaUpdate) for subsequent iterations. If I'm feeling ambitious, I will put it in a build script but usually, I just add an [Ignore] attribute. If you use ReSharper, you can position the cursor on this test, press Alt-R-U-R and it will run this specific test for you, regardless of whether it's ignored or not.


Also, this creates only the tables, no stored procedures. If you're using NHibernate (which I assume you do since this is a Sharp forum), they are largely unnecessary except possibly for reporting.
Kyle Baley
ky...@baley.org
403.770.9563
http://kyle.baley.org

FlyAtDusk

unread,
Nov 26, 2009, 9:14:39 AM11/26/09
to S#arp Architecture
thanks guys. i'm beginning to spec out porting an existing application
to this new architecture. there are more than 300 tables, along with
many views, involved. this database already exists and has been in
production for 3 years or so. it sure seems like a whole lot of work
is going to be needed if i'm to go with s#arp.

Kyle Baley

unread,
Nov 26, 2009, 11:42:09 AM11/26/09
to sharp-arc...@googlegroups.com
That'll be quite a bit of work in any scenario if you're working with an existing database, not just with Sharp.


--

You received this message because you are subscribed to the Google Groups "S#arp Architecture" group.
To post to this group, send email to sharp-arc...@googlegroups.com.
To unsubscribe from this group, send email to sharp-architect...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sharp-architecture?hl=en.


alberto rodriguez

unread,
Nov 26, 2009, 4:14:45 PM11/26/09
to S#arp Architecture
You can also use [Explicit]

On 26 nov, 15:10, Kyle Baley <k...@baley.org> wrote:
> Yeah, I pretty much do the same thing. I think NHibernate also has a way of
> updating the schema (SchemaUpdate) for subsequent iterations. If I'm feeling
> ambitious, I will put it in a build script but usually, I just add an
> [Ignore] attribute. If you use ReSharper, you can position the cursor on
> this test, press Alt-R-U-R and it will run this specific test for you,
> regardless of whether it's ignored or not.
>
> Also, this creates only the tables, no stored procedures. If you're using
> NHibernate (which I assume you do since this is a Sharp forum), they are
> largely unnecessary except possibly for reporting.
>
> > 2009/11/26 FlyAtDusk <flyatd...@yahoo.co.uk>
>
> > please bear with me on this, i'm still a newbie!
>
> >> in my traditional 3-tier apps, i was accustomed to running a code
> >> generator against an existing database and getting everything (all my
> >> entities etc) from that as a starting point from the one click...sql
> >> for stored procs, dal, bll and ui. therefore, i had to manually create
> >> the d/base first and work up from there. this is/was no great deal
> >> since sql server has a great interface for creating tables,
> >> relationships etc.
>
> >> with ddd, however, and using the t4 templates, i seem to need to first
> >> create the entities, manually, one by one, by tweaking the template(s)
> >> and after that, create the tables manually, one by one, then create
> >> the stored procedures, etc. is this the case? seems like (relatively)
> >> a lot of work. or is there something i'm missing?
>
> >> please excuse if this is a silly question.
>
> >> --
>
> >> You received this message because you are subscribed to the Google Groups
> >> "S#arp Architecture" group.
> >> To post to this group, send email to sharp-arc...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> sharp-architect...@googlegroups.com<sharp-architecture%2Bunsu...@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/sharp-architecture?hl=en.
>
> > --
> >http://www.failbettergames.com
>
> >http://www.fallenlondon.com
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "S#arp Architecture" group.
> > To post to this group, send email to sharp-arc...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > sharp-architect...@googlegroups.com<sharp-architecture%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/sharp-architecture?hl=en.
>
> --
> Kyle Baley
> k...@baley.org
> 403.770.9563http://kyle.baley.org
Reply all
Reply to author
Forward
0 new messages