<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    blogjava's web log

    blogjava's web log
    ...

    Nhibernate例[導(dǎo)入]

    // vo


    /**/ /// ?create?table?tabletest(id?int,name?varchar(20),
    ????
    /// ?age?int,sex?varchar(20));

    ???? public ? class ?Tabletest
    ????
    {
    ????????
    private ? int ?id;
    ????????
    private ? string ?name;
    ????????
    private ? int ?age;
    ????????
    private ? string ?sex;


    //前臺
    private?void?button1_Click(object?sender,?System.EventArgs?e)
    ????????
    {
    ????????????
    //添家字段
    ????????????VO.Tabletest?vo=new?VO.Tabletest();
    ????????????vo.Id
    =int.Parse?(this.textBox1.Text?);
    ????????????vo.Name?
    =this.textBox2.Text?;
    ????????????vo.Age?
    =int.Parse(this.textBox3.Text?);
    ????????????vo.Sex?
    =this.textBox4.Text?;
    ????????????BLL.TableTestBll?bll
    =new?BLL.TableTestBll();
    ????????????bll.addTableTest(vo);
    ????????????
    this.dataGrid1?.DataSource=bll.getTableTest();
    ????????}


    ????????
    private?void?button2_Click(object?sender,?System.EventArgs?e)
    ????????
    {
    ????????????
    //刪除一條
    ????????????BLL.TableTestBll?bll=new?BLL.TableTestBll();
    ????????????
    string?srt=this.dataGrid1[this.dataGrid1.CurrentRowIndex,0].ToString();
    ????????????bll.remove(
    int.Parse?(srt));
    ????????????
    this.dataGrid1?.DataSource=bll.getTableTest();
    ????????}


    ????????
    private?void?button3_Click(object?sender,?System.EventArgs?e)
    ????????
    {
    ????????????
    //更新
    ????????????VO.Tabletest?vo=new?VO.Tabletest();
    ????????????vo.Id
    =int.Parse?(this.textBox1.Text?);
    ????????????vo.Name?
    =this.textBox2.Text?;
    ????????????vo.Age?
    =int.Parse(this.textBox3.Text?);
    ????????????vo.Sex?
    =this.textBox4.Text?;
    ????????????BLL.TableTestBll?bll
    =new?BLL.TableTestBll();
    ????????????bll.updataTable(vo);
    ????????????
    this.dataGrid1?.DataSource=bll.getTableTest();
    ????????}


    ????????
    private?void?button5_Click(object?sender,?System.EventArgs?e)
    ????????
    {
    ????????????
    //得到
    ????????????BLL.TableTestBll?bll=new?BLL.TableTestBll();
    ????????????
    this.dataGrid1.DataSource?=bll.getTableTest();
    ????????}




    using?System;
    using?NHibernate;
    using?System.Collections?;
    using?VO;

    namespace?BLL
    {
    ????
    ///?<summary>
    ????
    ///?Class1?的摘要說明。
    ????
    ///?</summary>

    ????public?class?TableTestBll
    ????
    {
    ????????
    public?TableTestBll()
    ????????
    {
    ????????}


    ????????
    public?NHibernate.ISession?getSession()
    ????????
    {
    ????????????NHibernate.Cfg.Configuration?cfg
    =new?NHibernate.Cfg.Configuration();
    ????????????cfg.Configure();
    ????????????NHibernate.ISessionFactory?sess
    =cfg.BuildSessionFactory();
    ????????????NHibernate.ISession?iss
    =sess.OpenSession();
    ????????????
    return?iss;
    ????????}

    ????????
    public?System.Collections.IList?getTableTest()
    ????????
    {
    ????????????NHibernate.ISession?sess
    =this.getSession();
    ????????????IList?list
    =sess.Find("from?Tabletest?t");
    ????????????
    return?list;
    ????????}

    ????????
    public?void?addTableTest(VO.Tabletest?vo)
    ????????
    {
    ????????????NHibernate.ISession?sess
    =this.getSession();
    ????????????sess.Save(vo,vo.Id);
    ????????????sess.Flush();
    ????????}

    ????????
    public?void?remove(int?id)
    ????????
    {
    ????????????NHibernate.ISession?sess
    =this.getSession();
    ????????????sess.Delete?(
    "from?Tabletest?t?where?t.Id="+id);
    ????????????sess.Flush();
    ????????}

    ????????
    public?void?updataTable(Tabletest?t)
    ????????
    {
    ????????????NHibernate.ISession?sess
    =this.getSession();
    ????????????Tabletest?tt
    =(Tabletest)sess.Load(t.GetType(),t.Id);
    ????????????tt.Name?
    =t.Name?;
    ????????????tt.Age?
    =t.Age?;
    ????????????tt.Sex?
    =t.Sex?;
    ????????????sess.SaveOrUpdate(tt);
    ????????????sess.Flush();
    ????????}

    ????}

    }



    配置文件

    <?xml?version="1.0"?encoding="utf-8"??>
    <hibernate-configuration??xmlns="urn:nhibernate-configuration-2.0"?>
    ????
    <session-factory?name="NHibernate.Test">
    ????????
    ????????
    <property?name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    ????????
    <property?name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    ????????
    <property?name="connection.connection_string">Server=.;initial?catalog=student1;User?Id=sa;Password=</property>
    ????????
    <property?name="show_sql">true</property>
    ????????
    <property?name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
    ????????
    <property?name="use_outer_join">true</property>
    ????????
    ????????
    <property?name="query.substitutions">true?1,?false?0,?yes?1,?no?0</property>
    ????????
    <mapping?file="personVO.hbm.xml"?/>
    ????????????
    ????
    </session-factory>
    ????
    </hibernate-configuration>

    表的配置文件
    <?xml?version="1.0"?encoding="utf-8"??>
    <hibernate-mapping?xmlns="urn:nhibernate-mapping-2.0">
    ????
    <class?name="VO.Tabletest,VO"?table="Test">
    ????????
    <id?name="Id"?column="id">
    ????????????
    <generator?class="native"/>
    ????????
    </id>
    ????????
    <property?name="Name"?column="name"/>
    ????????
    <property?name="Age"?column="age"/>
    ????????
    <property?name="Sex"?column="sex"/>
    ????
    </class>
    </hibernate-mapping>

    posted on 2006-05-28 14:54 record java and net 閱讀(370) 評論(0)  編輯  收藏 所屬分類: dot net相關(guān)

    導(dǎo)航

    常用鏈接

    留言簿(44)

    新聞檔案

    2.動態(tài)語言

    3.工具箱

    9.文檔教程

    友情鏈接

    搜索

    最新評論

    主站蜘蛛池模板: 免费看国产成年无码AV片| 国产成人免费全部网站| 2020国产精品亚洲综合网| 日韩精品免费一区二区三区| 国产成人无码免费网站| 亚洲日本香蕉视频观看视频| 国产无遮挡吃胸膜奶免费看| 毛片在线全部免费观看| 99亚偷拍自图区亚洲| 久久亚洲国产精品五月天婷| 84pao国产成视频免费播放| 亚洲AV日韩AV永久无码色欲| 亚洲AV无一区二区三区久久| 国产一级淫片免费播放电影| 99re免费在线视频| 日韩免费码中文在线观看| 亚洲国产精品成人久久久 | 国产亚洲精AA在线观看SEE| 特级做A爰片毛片免费69| 中文在线免费看视频| 亚洲一卡2卡3卡4卡5卡6卡 | 久久91亚洲人成电影网站| 午夜毛片不卡高清免费| 99久久人妻精品免费一区| 午夜在线免费视频 | 亚洲黄色网站视频| 亚洲精品无码成人片在线观看| 免费观看国产网址你懂的| 国产免费久久精品99久久| 亚洲国产AV无码一区二区三区| 久久亚洲AV无码精品色午夜| 国产啪亚洲国产精品无码| 永久免费视频v片www| 国产成人精品久久免费动漫| 大地资源网高清在线观看免费| 美女裸免费观看网站| 亚洲色无码专区一区| 国产成人精品日本亚洲专区6| 久久水蜜桃亚洲av无码精品麻豆| 亚洲人成图片小说网站| MM131亚洲国产美女久久|