nhibernate
摘要: 条件查询 NHibernate.ICriteria接口表示特定持久类的一个查询。ISession是 ICriteria实例的工厂。 这里以Northwind数据库为示例数据库 示例数据表:Employees 现在只用雇员表中部分字段。 持久类如下: public class Employees { public virtual int EmployeeID { get; set; } public virtual string LastName { get; set; } public virtual string FirstName { get; set; } public vi...阅读全文
摘要: Restrictions.eq 等于 Restrictions.allEq 使用Map,使用key/value进行多个等于的比对 Restrictions.gt 大于 > Restrictions.ge 大于等于 >= Restrictions.lt 小于 < Restrictions.le 小于等于 <= Restrictions.between 对应SQL的BETWEEN子句 Restrictions.like 对应SQL的LIKE子句 Restrictions.in 对应SQL的in子句 Restrictions.and and关系 Restrictions.or阅读全文
摘要: 1.Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1这个异常是由于主键设置为自增长,而在我们插入记录的时候设置了ID的值导致的。即在映射文件中,设置 <id name="id" column="ID" type="inte阅读全文
摘要: 有很多时候我们需要多线程并发访问数据库,这样就存在访问冲突的问题,传统中的SQL可以用"for update"一类的语法实现数据锁定,在NHiberante里也有类似的实现方法,很简单,下面是一个例子方法,实现在事务里保证数据访问的独立性: privateIList<MailInfo>Load(intfirst,intcount){IList<MailInfo>list=newList<MailInfo>();if(count==0)returnlist;ISessionsession=DAORepository.Instrance.Db阅读全文
摘要: hibernate.cfg.xml 中hibernate.hbm2ddl.auto配置节点如下: <property name="hbm2ddl.auto">create-drop</property>update : auto execute SchemaUpdate on BuildSessionFactory create : auto execute SchemaExport on BuildSessionFactory create-drop : auto execute SchemaExport on BuildSessionFactor阅读全文
摘要: 使用nhibernate做update操作时出现如下错误: 此 SqlParameterCollection 的 Count=71 的索引 71 无效。XML文件<?xmlversion="1.0"encoding="utf-8"?><hibernate-mappingxmlns="urn:nhibernate-mapping-2.2"><classname="PERSON,Sgidi.Model"table="PERSON"><idname="阅读全文

