NHibernate的SchemaExport工具和配置()22条军规 [英] NHibernate SchemaExport and Configure() catch-22

查看:188
本文介绍了NHibernate的SchemaExport工具和配置()22条军规的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 DDD 在一个新的项目,第一种模式我的课,然后生成基于类库的数据库架构。我的计划是与NHibernate的先得用hbm2ddl工具的SchemaExport 做到这一点。

I want to use DDD in a new project and model my classes first, then generate the database schema based on the class library. My plan is to do this with the NHibernate hbm2ddl tool SchemaExport.

现在的问题是,我不能让的SchemaExport 来,因为一个奇怪的22条军规问题,它使我的工作。在的SchemaExport 要求配置对象,本身就需要一个有效的NHibernate的配置文件,以及一组数据库映射。

The problem is that I can't get the SchemaExport to work because of a weird catch-22 problem it puts me in. The SchemaExport requires a Configuration object that itself requires a valid NHibernate configuration file as well as a set of database mappings.

美中不足的-22在这里的是,当我做配置(),它抱怨无法确定表的实体myEntity所的名义,删除'表'属性或分配价值吧。所以配置()方法要求表中存在,而的SchemaExport 应该创建它根据配置,我不能创建,因为该表是不是不存在。

The catch-22 here is that when I do the Configure(), it complains "Could not determine the name of the table for entity 'MyEntity'; remove the 'table' attribute or assign a value to it." So the Configure() method requires the table to exist, while the SchemaExport is supposed to create it based on the Configuration that I can't create because the table isn't doesn't exist.

那么,如何在地球上我应该创建配置包含必需的的SchemaExport 映射到一个有效的NHibernate真正做一些有用的事情,而不必配置()抛出,并抱怨说,它无法找到要与的SchemaExport ?是否有这样就不会检查数据库的给定表存在一个模式我可以设置配置对象,还是有别的东西,我需要怎么办?

So, how on earth am I supposed to create a valid NHibernate Configuration containing the mappings required for SchemaExport to actually do something useful without having Configure() throw and complain that it can't find the tables that are to be created with SchemaExport? Is there a "mode" I can set the Configuration object in so it won't check the database for the existence of the given tables, or is there something else I need to do?

推荐答案

您可以发布您的配置文件?

Can you post your configuration file?

我用这个方法所有的时间,没有表present,和我能够快速生成模式。我的猜测是,你可能有一些掉在你.hbm文件之一。尽量减少您的架构下,以1台,得到它的工作,然后从那里建立起来。作为参考,这里是code我用它来生成数据库架构:

I use this method all the time with no tables present, and am able to generate the schema on the fly. My guess is that you may have something off in one of your .hbm files. Try cutting your schema down to 1 table, getting it to work, then building it up from there. As a reference, here is the code I use to generate the db schema:

    var cfg = new Configuration();
    cfg.Configure();
    var schema = new SchemaExport(cfg);
    schema.Create(true, true);

这也将推动脚本到控制台你,所以你可以看到哪些SQL是针对数据库生成的。

This will also push the script to the console for you, so you can see what SQL is generated against the db.

这篇关于NHibernate的SchemaExport工具和配置()22条军规的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆