• nhibernate3 linq的where操作 YI


    using NHibernate.Criterion;
    using NUnit.Framework;
    using NetworkMonitor.DAL.Business.Model;
    
    namespace NetworkMonitor.NunitTest.DAlTets
    {
        class 数据库操作LingWhere
        {
            //private NetworkMonitor.DAL.Core.MyServiceFactory.
            private readonly NetworkMonitor.DAL.Core.MyServiceFactory _service = NetworkMonitor.DAL.Core.MyServiceFactory.Instance;
    
            [Test]
            public void Where基本操作()
            {
                var bb = _service.GetTbUserService.Dao();
    
    
    
                bb.SessionFactory.GetSession().QueryOver<TbUser>().
                    //每个where之间用 and自动连接
                    // WHERE (this_.UserName = @p0 and this_.UserName = @p1)  
                    Where(c => c.UserName == "test" && c.UserName == "10")
                    .And(c => c.UserName == "99"|| c.UserName == "")
                    /*
                     * 建议 一次都放到where里面
                     */
    
                
                    //排序
                    .OrderBy(c => c.UserName).Asc
                    .List();
    
            }
            [Test]
            public void Where级联操作()
            {
                var bb = _service.GetTbUserService.Dao();
    
                //准备级联条件--
                /**/
                QueryOver<TbUser> lr刘瑞 =
                 QueryOver.Of<TbUser>()
                     .Where(oo => oo.UserName =="刘瑞").Select(oo =>oo.UserName);
    
    
                TbUser tbUser = null;
                var list =  bb.SessionFactory.GetSession().QueryOver<TbUser>()
     
                    .WithSubquery.WhereProperty(c => c.UserName).NotIn(lr刘瑞)//没有刘瑞的数据
    
    
    
                    //排序
                     //.OrderBy(c => c.UserName).Asc
                    .List();
    
                foreach (var user in list)
                {
                   // Assert.AreEqual(user.UserName,"刘瑞");
                    System.Console.WriteLine(user.UserName);
                }
            }
    
            [Test]
            public void Where多表联操作()
            {
                var bb = _service.GetTbUserService.Dao();
    
                //准备级联条件--
                /**/
                QueryOver<TbUserRole> lrXX =
                 QueryOver.Of<TbUserRole>().
                        Select(oo => oo.UId);
    
    
                TbUser tbUser = null;
                var list = bb.SessionFactory.GetSession().QueryOver<TbUser>()
    
                    .WithSubquery.WhereProperty(c => c.Id).Eq(lrXX)//只有XX的数据
                 //排序
                    //.OrderBy(c => c.UserName).Asc
                    .List();
    
                foreach (var user in list)
                {
                    // Assert.AreEqual(user.UserName,"X11X");
                    System.Console.WriteLine(user.UserName);
                }
            }
        }
    }
  • 相关阅读:
    文本效果
    C# 将数据导出到Execl汇总[转帖]
    using方法的使用
    存储过程的相关记录
    Dictionary 泛型字典集合[转帖]
    JS验证
    浅谈AutoResetEvent的用法 [转帖]
    聊聊xp和scrum在实战中的应用问题
    字体下载
    [转] 前端开发工程师如何在2013年里提升自己
  • 原文地址:https://www.cnblogs.com/loswing/p/2475517.html
Copyright © 2020-2023  润新知