首页 > 代码库 > NHibernate的使用
NHibernate的使用
hibernate.cfg.xml
1 <?xml version="1.0" encoding="utf-8" ?> 2 <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > 3 <session-factory name="NHibernate.Test"> 4 <property name="connection.connection_string"> 5 Data Source=.;database=NHibernate;Integrated Security=True;Pooling=False 6 </property> 7 <property name="show_sql">true</property> 8 <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> 9 <mapping assembly="NHibernateSpringTest"/>10 </session-factory>11 </hibernate-configuration>
User.hbm.xml
1 <?xml version="1.0" encoding="utf-8" ?> 2 <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> 3 <class name="NHibernateSpringTest.User, NHibernateSpringTest" table="my_users"> 4 <id name="LoginId" column="LogonId" type="String" length="20"> 5 <generator class="assigned" /> 6 </id> 7 <property name="UserName" column="UserName" type="String" length="40"/> 8 <property name="Age" column="Age" type="Int32"/> 9 </class>10 </hibernate-mapping>
Program.cs
1 Configuration cfg = new Configuration().Configure();2 ISessionFactory factory = cfg.BuildSessionFactory();3 ISession session = factory.OpenSession();4 //1.Search5 User singleUser = (User)session.Get(typeof(User), "andy");6 Console.WriteLine("name:{0},age:{1}", singleUser.UserName, singleUser.Age);
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。