在使用以前我本身的电脑环境是64位,64位的oracle,32位的客户端。因此报了一个错误。我在网上找到这个哥们的博客html
http://www.cnblogs.com/joey0210/archive/2012/08/15/2640248.html ,问题是同样的,状况也是同样的,我感受多是权限问题,我还在调试中。上面的问题一搜一大推解决方法程序员
将项目生成改成x86的便可
数据库
这种传统的建立ISessionFactory的方法适用于前面的特性映射,xxx.hbm.xml映射文件这类的映射方式,可是Fluent这种映射方式须要不同方法建立ISessionFactory,好咱们如今先说传统的方式。c#
public class SessionFactory { private static ISessionFactory sessionFactory { get; set; } public static ISessionFactory GetCurrentFactory() { if (sessionFactory == null) { sessionFactory = CreateSessionFactory(); } return sessionFactory; } private static ISessionFactory CreateSessionFactory() { return new Configuration().Configure().BuildSessionFactory(); //上一篇说了,若是你的配置文件不在根目录那么就须要手动的调用这个文件的位置 //Configuration cfg = new Configuration().Configure(filePath); } }
后面的用法 void AddPost() {// initialize the configuration Configuration cfg = new Configuration(); cfg.AddAssembly("NHClass"); ISessionFactory factory = cfg.BuildSessionFactory(); // start a session with the database// the ISession object represents a connection to your backend database ISession session = factory.OpenSession(); // the ITransaction object represents a NH Managed transaction// always start a transaction before u want to do something on the backend database ITransaction trans = session.BeginTransaction();// initialize ur Post Post post = new Post(); post.PostID = Guid.NewGuid(); post.Title = "hello Nibernate"; post.Content = "foo test"; post.Creator = "foo"; post.LastUpdator = "bar"; post.CreateDate = System.DateTime.Now.Date; post.LastUpdateDate = System.DateTime.Now.Date;// store the new post session.Save(post);// commit the transaction trans.Commit();// end the session session.Close(); }
这部分写的时候须要写那个数据库主键选择策略
session
在建立的时候遇到一个问题oracle
网上不少解决方法,有一种说法是这样的,不过我再测试好像不行
app
oh,困扰了一天的问题终于解决了,哎,看来这贴是发错地方了,居然没人理。
ISessionFactory factory = Configuration.BuildSessionFactory();
要在注册了实体之后调用,否则这个工厂建立出来的ISession是不认识这些持久化类的,哎,调试一天,最后才发现。。 工具
http://bbs.csdn.net/topics/330269091 要post
要注意更层之间的引用问题,别少引用了东西
学习
上面的演示相信你们都能看明白,二者之间的对比也比较明显的显露出来,传统的方式咱们只须要编写正确的配置文件,相对比较灵活,一些修改的话均可以在配置 文件中进行更新,好比Mappings,而上面的代码,Fluent虽然使用代码的方式进行了配置,省去了配置文件,但灵活性却没有传统方式那么好,修改 一些配置的时候,咱们得扩充咱们的CreateSessionFactory的方法,不过Fluent更符合人类的思考行为,并且有VS这么强大IDE, 在编写代码的同时,可以享受强大的智能感知。
二者之间都各有长短,或许你尚未体会到Fluent的强大,在往后的Mappings时,你会慢慢了解为何他会叫Fluent。传统方式对于一些常常 使用的程序员来讲很是简便,加上代码生成工具,使用起来也会游刃有余,但对于新手来讲,Fluent绝对是一个好帮手。
4、灵活的Fluent
那咱们Fluent就没有办法灵活了吗?固然不,Fluent的开发者不只帮你保留了原有的方式,还能够混合你的配置文件,最有意思的时,你还可使用它 来学习NHibernate,甚至可使用它来开发你本身的自动代码生成工具,由于我也刚学,先介绍一些简单的,至于其余功能,但愿你们也能跟我一块儿学 习,体验Fluent带来的快感。
5支持的代码链接数据库的方式