This is my hibernate.cfg.xml file
<?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="hibernate.dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=FirstSample.sdf</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
I have single form with button, the following code snippet will be for button_Click
Configuration config = new Configuration().Configure();
config.AddAssembly((typeof(UserInfo).Assembly));
ISessionFactory sessionFactory = config.BuildSessionFactory();
ISession session = sessionFactory.OpenSession();
ITransaction transaction = session.BeginTransaction();
UserInfo currentUser = new UserInfo();
currentUser.Name = "Shyam Sundar";
currentUser.Password = "success";
currentUser.Email = "
[email protected]";
currentUser.Company = "HCL";
session.Save(currentUser);
transaction.Commit();
session.Close();
This is my UserInfo.Hbm.xml file:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="HibernatorSample" namespace="HibernatorSample">
<class name="UserInfo" >
<id name="Id" column="LoginId">
<generator class="assigned" />
</id>
<property name="Name" column="Name" type="String" length="50"/>
<property name="Password" type="String" length="20"/>
<property name="Email" column="Email" type="String" length="50"/>
<property name="Company" column="Company" type="String" length="50"/>
</class>
</hibernate-mapping>
I have created the table in local sql server. I have tried with various ways. Please suggest me a link, i need to run a sample application with nHibernate. Thanks for your help
Shyamdvk