日期:2014-05-20  浏览次数:20845 次

NHibernate 新手 肯定给分
一个新手, 写了一个 NHibernate 的程序,以前用过java的Hibernate, 突然感觉两个很想色,但是不一样

写了一个类,就是想把这个类插到MySQL的数据库里面,帮忙看看,怎么做呢

下面是程序的截图, 总是弹出来说让我找一个源代码, NHinernate 和 Iesi 都加进去了



这个是真个项目的结构图, NHinernate 和 Iesi 都加进去了, 怎么还要代码



相关的代码, 一个类, 一个映射文件*.hbm.xml, 一个hbm的配置文件, 还有就是主程序了


namespace Thiess.Data
{
        public class Product
        {
            public string m_ID { get; set; }
            public string m_Name { get; set; }
        }

}




static void Main(string[] args)
        {
            Product[] cs = new Product[MaxRow];
            for (int i = 1; i <= MaxRow; i++)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("用户");
                sb.Append(i);

                Product c = new Product();
                c.m_ID = i.ToString();
                c.m_Name = sb.ToString();


                cs[i - 1] = c;
            }

            Console.WriteLine("=================== TEST START ===================");




            Configuration cfg = new Configuration();

            ISession session = cfg.BuildSessionFactory().OpenSession();
            ITransaction transaction = session.BeginTransaction();


            session.Save(cs[0]);
            transaction.Commit();
            session.Close();
       }



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

  <!-- more mapping info here -->
  <class name="Product" table="Test_product_table" lazy="false">
    <id name="m_ID" column="Product_ID" type="string">
      <generator class="native" />
    </id>
    <property name="m_Name" column="Product_Name" type="string" length="20"/>
  </class>

</hibernate-mapping>




<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
    <property name="connection.connection_string">Data Source=FirstSample.sdf</property>

    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

------解决方案--------------------
感觉像是程序报错,要你调试源代码

你用Nuget 引用NHinernate 和 Iesi 试试
  
*****************************************************************************
http://feiyun0112.cnblogs.com/
------解决方案--------------------
试试