开发者

Can't find NHibernate mapping file: noob question

Struggling with NHibernate and would appreciate any help. I've got a table called 'orders' and a class called 'Order'. I'm using MVC3, and this is my exception

NHibernate.MappingException: Could not compile the mapping document: Orders.hbm.xml ---> System.IO.FileNotFoundException: Could not find file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\Orders.hbm.xml'.

(this is when I try to start the app). I'm guessing it's a) a problem with the mapping file itself and therefore not copying it to the IIS deployment folder, or I need to define it as some sort of 'embedde resorce' (which it is). Bit new to this...

My mapping file is in 'Mappings/Orders.hbm.xml' and looks like this

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="Munch"
                   namespace="Munch.Models">

  <class name="Order" table="orders">
    <id开发者_C百科 name="id">
      <generator class="int32" />
    </id>
    <property name="Name" />
  </class>

</hibernate-mapping>

If anyone can tell me what's wrong I will be really grateful (or even if you can tell me how to get some more info as to how to get more detail on the error)

Thanks

PS I'm from Java/Spring/JPA land but trying to put together a decent stack for my team. I'm hoping these .NET versions translate well to work with MVC3 in .NET land but if anyone wants to recommend better technologies I'm all ears!


It is a good idea to embed hbm file as resource into your assembly. In Visual Studio Solution Explorer:

Right click on Order.hbm.xml -> Properties -> Set Build Action = EmbeddedResource. And let NHibernate know about the location of hbm file by calling AddAssembly:

var config = new Configuration();
...
config.AddAssembly("AssemblyThatContainsOrders");

ISessionFactory sessionFactory = config.BuildSessionFactory();

See this for details. And the generator mapping should look like this:

<id name="id" column="Id" type="Int32">
    <generator class="native" />
</id>


Your generator declaration is wrong. See section 5.1.4 in the documentation for valid values for the generator class attribute.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜