Add dynamic-update="true" in configuration file on the class level node
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="TstDBConnection.Entities" assembly="TstDBConnection"> <class name="Course" table="Course" dynamic-update="true"> //<---------- here <id name="Id" column="Id"> <generator class="guid.comb"/> </id> <property name="Name" column="Name"></property> <property name="CreatedDate" column="CreatedOn"></property> </class> </hibernate-mapping>
public static void TestUpdate(ISessionFactory sessionFactory) { //Use NHibernate to create an entity and get a list of all entities using (ISession session = sessionFactory.OpenSession()) { Course emp = session.Load<Course>(new Guid("A3EEFCBE-0F0B-4939-9781-A0CA00F9BCA7")); emp.Name = "Tian"; session.SaveOrUpdate(emp); session.Flush(); var query = from course in session.Query<Course>() select course; IList<Course> courses = query.ToList(); } }