码迷,mamicode.com
首页 > Web开发 > 详细

【Nhibernate】入门 踩雷篇

时间:2015-07-11 22:41:31      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

总结(喜欢写在前面,记性不好老忘记解决问题时的思路):

使用框架一般不会完整的看文档,直接上来就搞,踩雷是必须的,重要的是遇到雷的时候要快速变换思路,是不是姿势不对(文件位置不对) 提高解决问题的速度。

官网的文章可信度还是挺高的,尽量的不要跑偏。

 

 

沿着官网 –> http://nhibernate.info/doc/tutorials/first-nh-app/your-first-nhibernate-based-application.html

开始coding

刚开始map放在 application下报:

No persister for: 

技术分享

 

单独的把model建一个项目

报:

Could not compile the mapping document

原因是我在解决问题的时候加了   <mapping assembly="HibernateService"/>

技术分享

 

技术分享

 

保留一处就好了

 

又出现下面问题:

技术分享

 

  public class Product
    {
        public virtual Guid Id { get; set; }
        public virtual string Name { get; set; }
        public virtual string Category { get; set; }
        public virtual bool Discontinued { get; set; }
    }

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="HibernateService"
                   namespace="HibernateService">
  <class name="Product" table="Product">
    <id name="Id">
      <generator class="guid" />
    </id>
    <property name="Name" />
    <property name="Category" />
    <property name="Discontinued" />
  </class>
  <!-- more mapping info here -->

</hibernate-mapping>

 

guid要小写

 

技术分享

写入成功!

 

 

技术分享

【Nhibernate】入门 踩雷篇

标签:

原文地址:http://www.cnblogs.com/viewcozy/p/4639398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!