views:

21

answers:

1

I want to export a schema from my types annotated with NHibernate attributes. Is this possible?

My current code is below, needless to say, it compiles, but the expected table TestType does not get created.

I have a type as follows:

    [Serializable, Class(Schema = "test")]    
    public class TestType
    {
        [Property]
        public Guid Id { get; set; }
        [Property]
        public string Value { get; set; }
    }

And my export code looks like this:

//...
cfg.AddAssembly(Assembly.Load("My.Assembly"));
new NHibernate.Tool.hbm2dd.SchemaExport(NHibernateConfiguration)
                          .Execute(false, true, false); 
//...
A: 

If your NHibernateConfiguration object has been configured correctly with the relevant class mappings, this will work:

new NHibernate.Tool.hbm2ddl.SchemaExport(NHibernateConfiguration).Create(false, true);

If the class mappings have not been set properly in the NHibernateConfiguration, then there will be no schema to create and hence it will appear the SchemaExport is not working.

Ben Aston