当前位置: 首页>>代码示例>>C#>>正文


C# ISession.CreateQuery方法代码示例

本文整理汇总了C#中ISession.CreateQuery方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.CreateQuery方法的具体用法?C# ISession.CreateQuery怎么用?C# ISession.CreateQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISession的用法示例。


在下文中一共展示了ISession.CreateQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetUp

        public void SetUp()
        {
            _session = _factory.OpenSession();
            _repository = new DynamicRepository<Person>(_session);

            _session.CreateQuery("delete from Book").ExecuteUpdate();
            _session.CreateQuery("delete from Movie").ExecuteUpdate();
            _session.CreateQuery("delete from Person").ExecuteUpdate();

            _book1 = new Book { Title = "book 1" };
            _book2 = new Book { Title = "book 2" };
            _book3 = new Book { Title = "book 3" };

            _movie1 = new Movie { Title = "movie 1" };
            _movie2 = new Movie { Title = "movie 2" };
            _movie3 = new Movie { Title = "movie 3" };

            _person1 = new Person { Name = "person 1" };
            _person2 = new Person { Name = "person 2" };
            _person3 = new Person { Name = "person 3" };

            _person1.FavoriteBooks.Add(_book1);
            _person1.FavoriteBooks.Add(_book2);
            _person2.FavoriteBooks.Add(_book3);

            _person1.FavoriteMovies.Add(_movie1);
            _person1.FavoriteMovies.Add(_movie2);
            _person2.FavoriteMovies.Add(_movie3);

            _person1.BFF = _person2;
            _person2.BFF = _person1;

            SaveEntities();
        }
开发者ID:erikojebo,项目名称:nhibernate.dynamic,代码行数:34,代码来源:DynamicRepositorySpecs.cs

示例2: TransitStats

 public TransitStats(ISession session)
 {
     ImagesCount = (int) session.CreateQuery("SELECT COUNT(i) FROM Image i").UniqueResult<long>();
     PostsCount = (int) session.CreateQuery("SELECT COUNT(p) FROM Post p").UniqueResult<long>();
     CommentsCount = (int) session.CreateQuery("SELECT COUNT(c) FROM Comment c").UniqueResult<long>();
     AtomCount = TransitCounter.GetNamedCounter(session, "Atom");
     RssCount = TransitCounter.GetNamedCounter(session, "Rss");
 }
开发者ID:dblock,项目名称:dblog,代码行数:8,代码来源:TransitStats.cs

示例3: GetResult

		private IList GetResult(ISession session)
		{
			var query1 = session.CreateQuery("from NodeKeyword nk");
			var query2 = session.CreateQuery("from NodeKeyword nk");

			var multi = session.CreateMultiQuery();
			multi.Add(query1).Add(query2);
			return multi.List();
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:9,代码来源:Fixture.cs

示例4: GetAverageMoviePrice

 static double GetAverageMoviePrice(ISession session)
 {
     var hql = @"select avg(m.UnitPrice)
           from Movie m";
       var query = session.CreateQuery(hql);
       return query.UniqueResult<double>();
 }
开发者ID:akhuang,项目名称:NHibernate,代码行数:7,代码来源:Program.cs

示例5: SelectWithWhereClause

		public void SelectWithWhereClause()
		{
			using (session = OpenSession())
			{
				User user1 = new User();
				user1.UserName = "User1";
				session.Save(user1);

				User user2 = new User();
				user2.UserName = "User2";
				session.Save(user2);

				BlogPost post = new BlogPost();
				post.Title = "Post 1";
				post.Poster = user1;
				session.Save(post);

				session.Flush();
				session.Clear();

				User poster = (User) session.Get(typeof (User), user1.ID);

				string hql = "from BlogPost b where b.Poster = :poster";
				IList list = session.CreateQuery(hql).SetParameter("poster", poster).List();
				Assert.AreEqual(1, list.Count);
				BlogPost retrievedPost = (BlogPost) list[0];
				Assert.AreEqual(post.ID, retrievedPost.ID);
				Assert.AreEqual(user1.ID, retrievedPost.Poster.ID);

				session.Delete("from BlogPost");
				session.Delete("from User");
				session.Flush();
				session.Close();
			}
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:35,代码来源:Fixture.cs

示例6: PJSBLOGInfo

        /// <summary>
        /// 查询票据识别表
        /// </summary>
        /// <param PJSBLOG="PJSBLOG">票据识别实体类</param>
        /// <returns>PJSBLOG 集合</returns>
        public IList<PJSBLOG> PJSBLOGInfo(PJSBLOG PJSBLOGInfo)
        {
            IList<PJSBLOG> result = null;
            string hql = "from PJSBLOG where 1=1 ";
            if (PJSBLOGInfo.ZHDM!=0)
            {
                hql += " and ZHDM = :ZHDM";
            }
            if (!string.IsNullOrEmpty(PJSBLOGInfo.ACCNO))
            {
                hql += " and ACCNO like :ACCNO";
            }
            using (_session = _sessionfactory.Session)
            {

                IQuery query = _session.CreateQuery(hql);
                if (PJSBLOGInfo.ZHDM != 0)
                {
                    query.SetInt32("ZHDM", PJSBLOGInfo.ZHDM);
                }
                if (!string.IsNullOrEmpty(PJSBLOGInfo.ACCNO))
                {
                    query.SetString("ACCNO", "%" + PJSBLOGInfo.ACCNO + "%");
                }
                result = query.List<PJSBLOG>();
            }
            return result;
        }
开发者ID:wisexie,项目名称:WCFDemo,代码行数:33,代码来源:PJSBLOGDal.cs

示例7: GetInfo

 //查询所有在树中显示
 public IList GetInfo(int cid)
 {
     Session = GetSession();
     return Session.CreateQuery("from info c where c.cid=:fn ")
            .SetInt32("fn", cid)
            .List();
 }
开发者ID:feidu,项目名称:CostumDic,代码行数:8,代码来源:HQL.cs

示例8: GetLeveBy

 //查询类型详细信息
 public IList GetLeveBy(int cid)
 {
     Session = GetSession();
     return Session.CreateQuery("from leve c where c.id=:fn ")
            .SetInt32("fn",cid)
            .List();
 }
开发者ID:feidu,项目名称:CostumDic,代码行数:8,代码来源:HQL.cs

示例9: QueryUsingReadonlyProperty

		public void QueryUsingReadonlyProperty()
		{
			using (session = OpenSession())
			{
				Nums nums1 = new Nums {ID = 1, NumA = 1, NumB = 2};
				session.Save(nums1);

				Nums nums2 = new Nums {ID = 2, NumA = 2, NumB = 2 };
				session.Save(nums2);

				Nums nums3 = new Nums {ID = 3, NumA = 5, NumB = 2 };
				session.Save(nums3);

				session.Flush();
				session.Clear();

				var nums = session.CreateQuery("from Nums b where b.Sum > 4").List<Nums>();

				Assert.That(nums.Count, Is.EqualTo(1));
				Assert.That(nums[0].Sum, Is.EqualTo(7));

				session.Delete("from Nums");
				session.Flush();
				session.Close();
			}
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:26,代码来源:Fixture.cs

示例10: ApplyTo

        public static IQuery ApplyTo(this ODataQueryOptions query, ISession session)
        {
            string from = "from " + query.Context.ElementClrType.Name + " $it" + Environment.NewLine;

            // convert $filter to HQL where clause.
            WhereClause where = ToFilterQuery(query.Filter);

            // convert $orderby to HQL orderby clause.
            string orderBy = ToOrderByQuery(query.OrderBy);

            // create a query using the where clause and the orderby clause.
            string queryString = from + where.Clause + orderBy;
            IQuery hQuery = session.CreateQuery(queryString);
            for (int i = 0; i < where.PositionalParameters.Length; i++)
            {
                hQuery.SetParameter(i, where.PositionalParameters[i]);
            }

            // Apply $skip.
            hQuery = hQuery.Apply(query.Skip);

            // Apply $top.
            hQuery = hQuery.Apply(query.Top);

            return hQuery;
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:26,代码来源:ODataQueryOptionExtensions.cs

示例11: GetDetail

 //查询详细信息
 public IList GetDetail(int id)
 {
     Session = GetSession();
     return Session.CreateQuery("from info c where c.id=:fn ")
            .SetInt32("fn",id)
            .List();
 }
开发者ID:feidu,项目名称:CostumDic,代码行数:8,代码来源:HQL.cs

示例12: GetByAnimeID

		public List<AniDB_Tag> GetByAnimeID(ISession session, int animeID)
		{
			var tags = session.CreateQuery("Select tag FROM AniDB_Tag as tag, AniDB_Anime_Tag as xref WHERE tag.TagID = xref.TagID AND xref.AnimeID= :animeID")
				.SetParameter("animeID", animeID)
				.List<AniDB_Tag>();

			return new List<AniDB_Tag>(tags);
		}
开发者ID:dizzydezz,项目名称:jmm,代码行数:8,代码来源:AniDB_TagRepository.cs

示例13: GetByAniDBAnimeID

        public List<VideoLocal> GetByAniDBAnimeID(ISession session, int animeID)
        {
            var vidfiles = session.CreateQuery("Select vl FROM VideoLocal as vl, CrossRef_File_Episode as xref WHERE vl.Hash = xref.Hash AND xref.AnimeID= :animeID")
                .SetParameter("animeID", animeID)
                .List<VideoLocal>();

            return new List<VideoLocal>(vidfiles);
        }
开发者ID:maz0r,项目名称:jmmserver,代码行数:8,代码来源:VideoLocalRepository.cs

示例14: GetByAnimeID

		public List<AniDB_Category> GetByAnimeID(ISession session, int animeID)
		{
			var cats = session.CreateQuery("Select cat FROM AniDB_Category as cat, AniDB_Anime_Category as xref WHERE cat.CategoryID = xref.CategoryID AND xref.AnimeID= :animeID")
				.SetParameter("animeID", animeID)
				.List<AniDB_Category>();

			return new List<AniDB_Category>(cats);
		}
开发者ID:dizzydezz,项目名称:jmm,代码行数:8,代码来源:AniDB_CategoryRepository.cs

示例15: GetByAnimeID

        public List<CustomTag> GetByAnimeID(ISession session, int animeID)
        {
            var tags = session.CreateQuery("Select tag FROM CustomTag as tag, CrossRef_CustomTag as xref WHERE tag.CustomTagID = xref.CustomTagID AND xref.CrossRefID= :animeID AND xref.CrossRefType= :xrefType")
                    .SetParameter("animeID", animeID)
                    .SetParameter("xrefType", (int)CustomTagCrossRefType.Anime)
                    .List<CustomTag>();

            return new List<CustomTag>(tags);
        }
开发者ID:maz0r,项目名称:jmmserver,代码行数:9,代码来源:CustomTagRepository.cs


注:本文中的ISession.CreateQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。