当前位置: 首页 > news >正文

dedecms 音乐网站模板html页面布局

dedecms 音乐网站模板,html页面布局,wordpress文章前添加图标,网站备案期1. 学习目的: 通过进一步学习nhibernate基础知识#xff0c;在实现单表CRUD的基础上#xff0c;实现两表之间one-to-many的关系. 2. 开发环境必要准备 开发环境: windows 2003,Visual studio .Net 2005,Sql server 2005 developer edition 必要准备: 学习上篇文章单…1.     学习目的: 通过进一步学习nhibernate基础知识在实现单表CRUD的基础上实现两表之间one-to-many的关系. 2.     开发环境必要准备 开发环境: windows 2003,Visual studio .Net 2005,Sql server 2005 developer edition 必要准备: 学习上篇文章单表操作    3 对上篇文章中部分解释  1在User.hbm.xml中class节点中有一个lazy的属性这个属性用于指定是否需要延迟加载lazy loading在官方文档中称为:lazy fecting.可以说延迟加载是nhibernate最好的特点因为它可以在父类中透明的加载子类集合这对于many-to-one的业务逻辑中真是方便极了。但是有些时候父类是不需要携带子类信息的。这时候如果也加载无疑对性能是一种损失。在映射文件的class节点中可以通过配置lazy属性来指定是否支持延迟加载这就更灵活多了。   2) 在User.hbm.xml中generate节点代表的是主键的生成方式上个例子中的”native”根据底层数据库的能力选择identity,hilo,sequence中的一个比如在MS Sql中使我们最经常使用的自动增长字段每次加1.  3) 在NHibernateHelper.cs中创建Configuration对象的代码new Configuration().Configure(E:\myproject\nhibernatestudy\simle1\NHibernateStudy1\NhibernateSample1\hibernate.cfg.xml)因为我是在单元测试中调试所以将绝对路径的配置文件传递给构造函数。如果在windows app或者web app可以不用传递该参数。  4 实现步骤  1确定实现的业务需求用户工资管理系统  2) 打开上篇文章中的NHibernateStudy1解决方案。向项目NhibernateSample1添加类Salary;代码如下 Salary.csusing System;using System.Collections.Generic;using System.Text;namespace NhibernateSample1{    public partial class Salary    {        int _id;        User _user;        int _year;        int _month;        int _envy;        decimal _money;        /**//// summary        /// 工资编号        /// /summary        public virtual int Id        {            get            {                return _id;            }            set            {                _id  value;            }        }        /**//// summary        /// 雇员        /// /summary        public virtual User Employee        {            get            {                return _user;            }            set            {                _user  value;            }        }        /**//// summary        /// 年度        /// /summary        public int Year        {            get            {                return _year;            }            set            {                _year  value;            }        }        /**//// summary        /// 月份        /// /summary        public int Month        {            get            {                return _month;            }            set            {                _month  value;            }        }        /**//// summary        /// 季度        /// /summary        public int Envy        {            get            {                return _envy;            }            set            {                _envy  value;            }        }        /**//// summary        /// 工资        /// /summary        public decimal Money        {            get            {                return _money;            }            set            {                _money  value;            }        }    }} 3) 更改User.cs,在User里面添加SalaryList属性 User.cs 1private System.Collections.IList _salaryList; 2 /**//// summary 3        /// 工资列表 4        /// /summary 5        public System.Collections.IList SalaryList 6        { 7            get 8            { 9                return _salaryList;10            }11            set12            {13                _salaryList  value;14            }15        } 4修改User.hbm.xml加入bag节点User.hbm.xmlbag nameSalaryList tableSalary inversetrue lazytrue cascadeall      key columnId/      one-to-many classNhibernateSample1.Salary,NhibernateSample1/one-to-many    /bag  5编写类Salary的映射文件:Salary.hbm.xml Salary.hbm.xml?xml version1.0 encodingutf-8 ?hibernate-mapping xmlnsurn:nhibernate-mapping-2.2  class nameNhibernateSample1.Salary,NhibernateSample1 tableSalary lazyfalse    id nameId columnId unsaved-value0      generator classnative /    /id    property nameYear columnYear typeInt32 not-nulltrue/property    property nameMonth  columnMonth  typeInt32 not-nulltrue/property    property nameEnvy  columnEnvy  typeInt32 not-nulltrue/property    property nameMoney  columnMoney  typeDecimal not-nulltrue/property    many-to-one nameEmployee columnUid not-nulltrue/many-to-one  /class/hibernate-mapping 6编写CRUD类UserSalaryFixure.csusing System;using System.Collections.Generic;using System.Text;using System.Collections;using NHibernate;using NHibernate.Cfg;using NHibernate.Tool.hbm2ddl;namespace NhibernateSample1{    public  class UserSalaryFixure    {        private ISessionFactory _sessions;         public void Configure()        {            Configuration cfg  GetConfiguration();                  _sessions  cfg.BuildSessionFactory();        }        Configuration GetConfiguration()        {            string cfgPath  E:\my project\nhibernate study\simle 1\NHibernateStudy1\NhibernateSample1\hibernate.cfg.xml;            Configuration cfg  new Configuration().Configure(cfgPath);            return cfg;        }        public void ExportTables()        {            Configuration cfg  GetConfiguration();                       new SchemaExport(cfg).Create(true, true);        }        public User CreateUser(String name,string pwd)        {            User u  new User();            u.Name  name;            u.Pwd  pwd;            u.SalaryList  new ArrayList();            ISession session  _sessions.OpenSession();            ITransaction tx  null;            try            {                tx  session.BeginTransaction();                session.Save(u);                tx.Commit();            }            catch (HibernateException e)            {                if (tx ! null) tx.Rollback();                throw e;            }            finally            {                session.Close();            }            return u;        }        public Salary CreateSalary(User u, int year,int month,int envy,decimal money)        {            Salary item  new Salary();            item.Year  year;            item.Money  money;            item.Envy  envy;            item.Month  month;            item.Employee  u;            u.SalaryList.Add(item);            ISession session  _sessions.OpenSession();            ITransaction tx  null;            try            {                tx  session.BeginTransaction();                session.Update(u);                tx.Commit();            }            catch (HibernateException e)            {                if (tx ! null) tx.Rollback();                throw e;            }            finally            {                session.Close();            }            return item;        }        public Salary CreateSalary(int uid,int year, int month, int envy, decimal money)        {            Salary item  new Salary();            item.Year  year;            item.Money  money;            item.Envy  envy;            item.Month  month;                        ISession session  _sessions.OpenSession();            ITransaction tx  null;            try            {                tx  session.BeginTransaction();                User u  (User)session.Load(typeof(User), uid);                item.Employee  u;                u.SalaryList.Add(item);                tx.Commit();            }            catch (HibernateException e)            {                if (tx ! null) tx.Rollback();                throw e;            }            finally            {                session.Close();            }            return item;        }        public Salary GetSalary(int salaryID)        {            ISession session  _sessions.OpenSession();            ITransaction tx  null;            try            {                tx  session.BeginTransaction();                Salary item  (Salary)session.Load(typeof(Salary),                    salaryID);                               tx.Commit();                return item;            }            catch (HibernateException e)            {                if (tx ! null) tx.Rollback();                return null;            }            finally            {                session.Close();            }            return null;        }        public User GetUser(int uid)        {            ISession session  _sessions.OpenSession();            ITransaction tx  null;            try            {                tx  session.BeginTransaction();                User item  (User)session.Load(typeof(User),                    uid);                tx.Commit();                return item;            }            catch (HibernateException e)            {                if (tx ! null) tx.Rollback();                return null;            }            finally            {                session.Close();            }            return null;        }        public void UpdateSalary(int salaryID, decimal money)        {            ISession session  _sessions.OpenSession();            ITransaction tx  null;            try            {                tx  session.BeginTransaction();                Salary item  (Salary)session.Load(typeof(Salary),                    salaryID);                item.Money  money;                tx.Commit();            }            catch (HibernateException e)            {                if (tx ! null) tx.Rollback();                throw e;            }            finally            {                session.Close();            }        }        public void Delete(int uid)        {            ISession session  _sessions.OpenSession();            ITransaction tx  null;            try            {                tx  session.BeginTransaction();                Salary item  session.Load(typeof(Salary), uid) as Salary; ;                session.Delete(item);                tx.Commit();            }            catch (HibernateException e)            {                if (tx ! null) tx.Rollback();                throw e;            }            finally            {                session.Close();            }        }    }} 7) 编写单元测试类UnitTest1.csUnitTest1.csusing System;using System.Text;using System.Collections.Generic;using Microsoft.VisualStudio.TestTools.UnitTesting;using NhibernateSample1;namespace TestProject1{    /**//// summary    /// UnitTest1 的摘要说明    /// /summary    [TestClass]    public class UnitTest1    {        public UnitTest1()        {            //            // TODO: 在此处添加构造函数逻辑            //        }        NhibernateSample1.UserSalaryFixure usf  new UserSalaryFixure();        其他测试属性#region 其他测试属性        //        // 您可以在编写测试时使用下列其他属性:        //        // 在运行类中的第一个测试之前使用 ClassInitialize 运行代码        // [ClassInitialize()]        // public static void MyClassInitialize(TestContext testContext) { }        //        // 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码        // [ClassCleanup()]        // public static void MyClassCleanup() { }        //        // 在运行每个测试之前使用 TestInitialize 运行代码         // [TestInitialize()]        // public void MyTestInitialize() { }        //        // 在运行每个测试之后使用 TestCleanup 运行代码        // [TestCleanup()]        // public void MyTestCleanup() { }        //        #endregion        [TestMethod]        public void Test1()        {            usf.Configure();            usf.ExportTables();            User u  usf.CreateUser(Guid.NewGuid().ToString(), ds);            Assert.IsTrue(u.Id0);            Salary s  usf.CreateSalary(u, 2007, 3, 1, (decimal)8000.00);            Assert.IsTrue(s.Id  0);            Salary s1  usf.CreateSalary(u.Id, 2007, 3, 1, (decimal)7500);            Assert.IsTrue(s1.Id0);            usf.UpdateSalary(s1.Id, (decimal)6000);            s1  usf.GetSalary(s1.Id);            Assert.IsTrue(s1.Money  (decimal)6000);            usf.Delete(s1.Id);            s1  usf.GetSalary(s1.Id);            Assert.IsNull(s1);            User u1  usf.GetUser(1);            Assert.IsTrue(u1.SalaryList.Count0);        }    }} 加载测试元数据直到Test()通过。总结通过进一步学习nhiberate发现ORM框架真是非常强大。今天先到这里。明天继续。项目文件:/Files/jillzhang/simple2.rar 转载于:https://www.cnblogs.com/erichzhou/archive/2007/03/29/692949.html
http://www.pierceye.com/news/264731/

相关文章:

  • vi设计公司网站python做网站好处
  • 北京专业网站建设服务商枣庄建设工程管理局网站
  • 百度移动网站提交深圳做网站的好公司
  • 十大在线编程网站旅游营销型网站
  • 微转app是用网站做的吗win10运行wordpress
  • 微网站建设哪里便宜网站做的跟别人的一样可以吗
  • 合肥优化网站福州网站设计
  • 企业网站制作前期需要什么资料网站 月15g流量够用吗
  • 网络营销网站建设ppt环艺做网站
  • 手机建设银行官方网站网站开发要点
  • 做简历的网站有随州网站建设学校
  • 深圳建设网站企业青白江做网站的公司
  • dm网站制作软件无忧网站建设
  • 如何在自己的网站上做歌单王建设医生网站
  • 科技+杭州+网站建设做效果图的网站有哪些
  • 引流推广网站平台wordpress页面发布失败
  • 南京哪家网站建设好网站开发需要注意的
  • 一个综合网站上线多少钱wordpress粘贴word
  • 承接电商网站建设新手做自己的网站
  • 网页版视频网站建设需要多少钱四川鸿业建设集团公司网站
  • h5网站实例wordpress改造mip
  • 完整的网络营销推广方案包括优化营商环境心得体会个人
  • 商洛市住房和城乡建设局网站建免费网站
  • 做网站要多少的服务器网站设计的步骤
  • 网站关键词怎么做上首页wordpress 架构原理
  • 厦门专业网站建设代理国外在线crm系统suitecrm
  • 哪个网站可以领手工活在家做wordpress heroku
  • 为什么没有网站做图文小说电子商务网站开发的课程介绍
  • 在哪个网站做问卷好单页面网站推广
  • 专业网站建设模块维护静海网站建设