public static IList<Mail> GetAllReals()
{
IList<Mail> list;
ISession session = NHelper.GetCurrentSession();
IQuery iq = session.CreateQuery("from M where Type = :type").SetString("type", "li");
list = iq.List<Mail>();
session.Close();
return list;
}新手,看不懂上面的代码。
ISession ,IQuery 是什么?CreateQuery在哪定义的?怎么连接的数据库?
list 又是什么?下面是GetCurrentSession的定义
public static ISession GetCurrentSession()
{
HttpContext context = HttpContext.Current; //system.web 命名空间下
ISession currentSession = context.Items[CurrentSessionKey] as ISession; // Items 是键值对 if (currentSession == null || !(currentSession.IsOpen)) // 先行如此。
{
currentSession = sessionFactory.OpenSession();
context.Items[CurrentSessionKey] = currentSession;
}
return currentSession;
}
{
IList<Mail> list;
ISession session = NHelper.GetCurrentSession();
IQuery iq = session.CreateQuery("from M where Type = :type").SetString("type", "li");
list = iq.List<Mail>();
session.Close();
return list;
}新手,看不懂上面的代码。
ISession ,IQuery 是什么?CreateQuery在哪定义的?怎么连接的数据库?
list 又是什么?下面是GetCurrentSession的定义
public static ISession GetCurrentSession()
{
HttpContext context = HttpContext.Current; //system.web 命名空间下
ISession currentSession = context.Items[CurrentSessionKey] as ISession; // Items 是键值对 if (currentSession == null || !(currentSession.IsOpen)) // 先行如此。
{
currentSession = sessionFactory.OpenSession();
context.Items[CurrentSessionKey] = currentSession;
}
return currentSession;
}
要不就是其他ORM.
里面内容:
<?xml version="1.0" encoding="utf-8"?>
<!--
This template was written to work with NHibernate.Test.
Copy the template to your NHibernate.Test project folder and rename it in hibernate.cfg.xml and change it
for your own use before compile tests in VisualStudio.
-->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.connection_string">
Server=(local);uid=aw;pwd=aw;database=aw;
</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<property name="show_sql">true</property>
<mapping assembly="NHModel"/>
</session-factory>
</hibernate-configuration>Nhibernate是什么?其他人留下的程序,这种程序从哪入手?应该学习什么?指个方向?
你去博客园找找李永京和刘冬的文章。。
NHelper.GetCurrentSession(); 是获取ISession接口的实例
session.CreateQuery()应该是获取对象的方法
我看过类似的代码。基本都把像CreateQuery()的实现封装成一个类 生成dll 加引用的 ,你看方法只能看到一个接口。真正的源码在dll里了。