• 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);
                }
            }
        }
    }
  • 相关阅读:
    SecureCRT上传文件到服务器 CentOS举例
    MongoDB关于replSet的配置概述(一主二从)
    MongoDB的安装与卸载与再安装……
    zip在python中的使用方法
    try,raise等的python的使用方法介绍
    【转】jQuery给动态添加的元素绑定事件的方法
    sublime的纵向操作(列操作)原来这么用
    Python 利用*args和**kwargs解决函数遇到不确定数量参数问题
    Python 函数式编程介绍
    Python list可以做什么
  • 原文地址:https://www.cnblogs.com/loswing/p/2475517.html
Copyright © 2020-2023  润新知