开发者

Nhibernate(Fluent) SchemaExport and SQlite Problem!

I am using Nhibernate(Fluent) with Sqlite and it worked with no problems what I have done:

  • Create the POCO EntityClasses for each table like this:

    public class tbl_Manufactor : BusinessObject<tbl_Manufactor>
    {
        public virtual string Name { get; set; }
    }
    

The Entity Classes all inherit from BusinessObject which contains the ID Property and simple CRUD functions I have also other 6 Entity Classes

  1. Create the Mappings with FluentHibernate like this:

    using Database.Entitites;
    using FluentNHibernate.Mapping;
    
    namespace Database.Mappings
    {
        public class tbl_ManufactorMap : ClassMap<tbl_Manufactor&开发者_StackOverflow社区gt;
        {
            public tbl_ManufactorMap()
            {
                Id(x => x.ID);
                Map(x => x.Name);
            }
        }
    }
    
  2. Create the Fluent Config like this:

 var Config = Fluently.Configure()
            .Database(SQLiteConfiguration.Standard  
                .ConnectionString(c=>c.FromConnectionStringWithKey("dbconnection"))  
                .ShowSql())  
            .Mappings(m =>  
                m.FluentMappings.AddFromAssemblyOf<tbl_Manufactor>())     
            .ExposeConfiguration(cfg =>  _configuration = cfg)  

            sessionFactory = Config.BuildSessionFactory();
  1. Do a SchemaExport to Create the Schema with:

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

Then Nhibernate created a fully working SQlite Database with the right tables!

But then I wanted to add 2 entity classes(I have done it in the same way as before) but when I run my test(which created my first database schema) it not add the new classes(tables) to the database!

The craziest thing is, that the test is always deleting any created database and recreate it with SchemaExport every time I run the test.

Could someone help me?


You also have the option of using Execute directly for database updates:

bool script = false;
bool update = true;
new SchemaExport(_configuration).Execute(script, update);

Edit: Make sure the mapping classes are public.


Sqlite in memory only exists for the life time of the connection. So for each new connection you need to start from the beginning.

I know two solutions for this. One is to only use a single session (and connection) for the unit tests. The other is what I did: I implemented a connection provider which always returns the same connection.


You could check the following : - Are the new entity classes in the same assembly ? - Check also for a loop in the model.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜