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


C# SqlBuilder.Where方法代码示例

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


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

示例1: List

        /// <summary>
        /// The list of results.
        /// </summary>
        /// <param name="maxResults">The max results.</param>
        /// <param name="start">The start</param>
        /// <param name="finish">The finish</param>
        /// <param name="orderBy">The order by.</param>
        /// <returns>The result set</returns>
        public override IEnumerable<Guid> List(
            int maxResults,
            DateTime? start = null,
            DateTime? finish = null,
            ListResultsOrder orderBy = ListResultsOrder.Descending)
        {
            var builder = new SqlBuilder();
            var t = builder.AddTemplate("select Id from MiniProfilers /**where**/ /**orderby**/ LIMIT(" + maxResults + ")");

            if (start != null)
            {
                builder.Where("Started > @start", new { start });
            }
            if (finish != null)
            {
                builder.Where("Started < @finish", new { finish });
            }

            builder.OrderBy(orderBy == ListResultsOrder.Descending ? "Started desc" : "Started asc");

            using (var conn = GetOpenConnection())
            {
                return conn.Query<Guid>(t.RawSql, t.Parameters).ToList();
            }
        }
开发者ID:haroonxml,项目名称:dotnet,代码行数:33,代码来源:SqliteMiniProfilerStorage.cs

示例2: Test5

        public void Test5()
        {
            var sqlBuilder = new SqlBuilder();
            var temp = sqlBuilder.AddTemplate("select * from test where /**where**/ and id = @0", 1);
            var temp2 = sqlBuilder.AddTemplate("select * from test2 where /**where**/ and id = @0", 1);

            Assert.AreEqual(1, temp.Parameters.Length);
            Assert.AreEqual("select * from test where  1=1  and id = @0", temp.RawSql);

            sqlBuilder.Where("id2 = @0", 2);

            Assert.AreEqual(2, temp2.Parameters.Length);
            Assert.AreEqual("select * from test2 where  ( id2 = @1 )\n and id = @0", temp2.RawSql);
        }
开发者ID:rplaner,项目名称:NPoco,代码行数:14,代码来源:SqlBuilderTests.cs

示例3: Test6

        public void Test6()
        {
            var sqlBuilder = new SqlBuilder();
            var temp = sqlBuilder.AddTemplate("select * from test where /**where**/ and id = @0", 1);
            var temp2 = sqlBuilder.AddTemplate("select * from test2 where /**where**/ and id = @0", 1);

            sqlBuilder.Where("id2 = @0", 2);

            Sql sql1 = temp;
            Assert.AreEqual(2, sql1.Arguments.Length);
            Assert.AreEqual("select * from test where  ( id2 = @1 )\n and id = @0", sql1.SQL);

            sqlBuilder.Where("id3 = @0", 3);

            Sql sql2 = temp2;
            Assert.AreEqual(3, sql2.Arguments.Length);
            Assert.AreEqual("select * from test2 where  ( id2 = @1 AND id3 = @2 )\n and id = @0", sql2.SQL);
        }
开发者ID:rplaner,项目名称:NPoco,代码行数:18,代码来源:SqlBuilderTests.cs

示例4: Test10

        public void Test10()
        {
            var sqlBuilder = new SqlBuilder();
            var temp = sqlBuilder.AddTemplate("select * from test where /**where**/ and id = @0", 1);

            sqlBuilder.Where("id2 = 2 OR id2 = 3");
            sqlBuilder.Where("id2 = 4");

            Assert.AreEqual(1, temp.Parameters.Length);
            Assert.AreEqual("select * from test where ( id2 = 2 OR id2 = 3 ) AND ( id2 = 4 )\n and id = @0", temp.RawSql);
        }
开发者ID:roadrunner75,项目名称:NPoco,代码行数:11,代码来源:SqlBuilderTests.cs

示例5: Index

        /// <summary>
        /// GET: /search
        /// GET: /search/index
        /// </summary>
        /// <returns></returns>
        public ActionResult Index(string input, int? page, int? pageSize)
        {
            ViewBag.Input = input;

            page = Math.Max(page ?? 1, 1); // Adjust.
            pageSize = Math.Max(Math.Min(pageSize ?? 10, 100), 10); // Adjust.

            int start = ((page.Value - 1) * pageSize.Value) + 1;
            int finish = page.Value * pageSize.Value;
            var builder = new SqlBuilder();
            SqlBuilder.Template pager = null, counter = null;

            pager = builder.AddTemplate("SELECT * FROM (SELECT /**select**/, ROW_NUMBER() OVER (/**orderby**/) AS RowNumber FROM Questions Q /**where**/) AS Results WHERE RowNumber BETWEEN @start AND @finish ORDER BY RowNumber",
                new { start = start, finish = finish });

            counter = builder.AddTemplate("SELECT COUNT(*) FROM Questions Q /**where**/");

            builder.Select("Q.*");
            builder.OrderBy("Q.Time DESC");
            builder.Where("Q.Title LIKE @searchInput OR Q.Answer LIKE @searchInput", new { searchInput = "%" + input + "%" });

            var results = Current.DB.QueryMultiple(pager.RawSql, pager.Parameters).Read<Question>();
            var totals = Current.DB.Query<int>(counter.RawSql, counter.Parameters).First();

            ViewData["Href"] = "/search?";

            return View(new PagedList<Question>(results, page.Value, pageSize.Value, false, totals));
        }
开发者ID:friedr1c3,项目名称:simple-faq,代码行数:33,代码来源:SearchController.cs

示例6: BuildSQL

		private static void BuildSQL(string firstName = null, string lastName = null)
		{
			var builder = new SqlBuilder();
			var template = builder.AddTemplate("Select * from Contacts /**where**/ ");
		
			if (firstName != null)
				builder.Where("FirstName LIKE '%' + @FirstName + '%'", new { FirstName = firstName });

			if (lastName != null)
				builder.Where("LastName LIKE '%' + @LastName + '%'", new { LastName = lastName });

			using (var cn = new SqlConnection(CONNECTION_STRING))
			{
				cn.Open();
				var c = cn.Query<Contact>(template.RawSql, template.Parameters);
				Console.WriteLine("Found {0} contacts", c.Count());
			}


			Console.ReadKey();
		}
开发者ID:jonathantower,项目名称:dapper,代码行数:21,代码来源:DapperSQLBuilder.cs

示例7: Test3

        public void Test3()
        {
            var sqlBuilder = new SqlBuilder();
            var temp = sqlBuilder.AddTemplate("select * from test where /**where**/ and id = @0", 1);

            var test = new[] {1, 2};
            sqlBuilder.Where("id2 in (@test)", new { test });

            Assert.AreEqual("select * from test where  ( id2 in (@0,@1) )\n and id = @0", temp.RawSql);
            Assert.AreEqual(2, temp.Parameters.Length);

            Console.WriteLine(temp.RawSql);
        }
开发者ID:rplaner,项目名称:NPoco,代码行数:13,代码来源:SqlBuilderTests.cs

示例8: Test1

        public void Test1()
        {
            var b = new SqlBuilder();
            var p = new {a = 123};
            var t = b.AddTemplate("select @a {{WHERE}}", p);

            b.Where("@b = @c", new {b = "abc", c = "abc"});

            int res;
            using (var db = new SqlConnection(ConnectionStrings.Default))
                res = db.Query<int>(t.RawSql, t.Parameters).Single();
            Assert.AreEqual(p.a, res);
        }
开发者ID:ronnieoverby,项目名称:UniqueNamespace.SqlBuilder,代码行数:13,代码来源:DapperTests.cs

示例9: Test12

        public void Test12()
        {
            var sqlBuilder = new SqlBuilder(new Dictionary<string, string>()
                                            {
                                                {"where(test)", "1<>1"}
                                            });

            var temp = sqlBuilder.AddTemplate("select * from test where /**where(test)**/ and id = @0", 1);

            sqlBuilder.Where("id2 = 4");

            Assert.AreEqual(1, temp.Parameters.Length);
            Assert.AreEqual("select * from test where  1<>1  and id = @0", temp.RawSql);
        }
开发者ID:joonhwan,项目名称:NPoco,代码行数:14,代码来源:SqlBuilderTests.cs

示例10: Main

        public static void Main()
        {
            using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection))
            {
                sqlConnection.Open();
                var builder = new SqlBuilder();

                // /**select**/  -- has to be low case
                var selectSupplierIdBuilder = builder.AddTemplate("Select /**select**/ from Suppliers /**where**/ ");
                builder.Select("Id");
                builder.Where("City = @City", new { City = "Tokyo"}); // pass an anonymous object

                var supplierIds = sqlConnection.Query<int>(selectSupplierIdBuilder.RawSql,
                                                           selectSupplierIdBuilder.Parameters);

                ObjectDumper.Write(supplierIds);

                sqlConnection.Close();

            }
        }
开发者ID:mehmetzantur,项目名称:dapper-net-sample,代码行数:21,代码来源:Contrib_SqlBuilder.cs

示例11: FindDinners

        private PagedList<Dinner> FindDinners(string where, object parameters, string orderBy = "DinnerID", int page = 1, int pageSize = 20)
        {
            using (var connection = MvcApplication.GetOpenConnection())
            {
                var builder = new SqlBuilder();

                var start = (page - 1) * pageSize + 1;
                var finish = page * pageSize;

                var selectTemplate = builder.AddTemplate(pagedQuery, new { start, finish });
                var countTemplate = builder.AddTemplate(totalQuery);

                builder.Where(where, parameters);

                builder.OrderBy(orderBy);

                var results = connection.Query<Dinner>(selectTemplate.RawSql, selectTemplate.Parameters);
                var count = connection.Query<int>(countTemplate.RawSql, countTemplate.Parameters).First();

                return new PagedList<Dinner>(results, page, count, pageSize);
            }
        }
开发者ID:jasonlin,项目名称:dapperDinner,代码行数:22,代码来源:DapperDinnerRepository.cs

示例12: Index

        public ActionResult Index(string sitename, string order_by, string q, int? page, int? pagesize)
        {
            Site = GetSite(sitename);

            if (Site == null)
            {
                return PageNotFound();
            }

            QuerySearchCriteria searchCriteria = new QuerySearchCriteria(q);

            if (string.IsNullOrEmpty(order_by))
            {
                if (searchCriteria.IsValid)
                    order_by = searchCriteria.IsFeatured ? "featured" : "recent";
                else
                    order_by = "featured";
            }

            ViewData["Site"] = Site;
            SelectMenuItem("Queries");
            SetHeader(
                "All Queries",
                new SubHeaderViewData
                {
                    Description = "featured",
                    Title = "Interesting queries selected by the administrators",
                    Href = "/" + sitename + "/queries?order_by=featured",
                    Selected = (order_by == "featured")
                },
                new SubHeaderViewData
                {
                    Description = "recent",
                    Title = "Recently saved queries",
                    Href = "/" + sitename + "/queries?order_by=recent",
                    Selected = (order_by == "recent")
                },
                new SubHeaderViewData
                {
                    Description = "favorite",
                    Title = "Favorite saved queries",
                    Href = "/" + sitename + "/queries?order_by=favorite",
                    Selected = (order_by == "favorite")
                },
                new SubHeaderViewData
                {
                    Description = "popular",
                    Title = "Saved queries with the most views",
                    Href = "/" + sitename + "/queries?order_by=popular",
                    Selected = (order_by == "popular")
                },
                new SubHeaderViewData
                {
                    Description = "everything",
                    Title = "All queries recently executed on the site",
                    Href = "/" + sitename + "/queries?order_by=everything",
                    Selected = (order_by == "everything")
                }
            );

            pagesize = Math.Max(Math.Min(pagesize ?? 50, 100), 10);
            page = Math.Max(page ?? 1, 1);

            int start = ((page.Value - 1) * pagesize.Value) + 1;
            int finish = page.Value * pagesize.Value;
            bool useLatest = true;
            var builder = new SqlBuilder();
            SqlBuilder.Template pager = null, counter = null;

            if (order_by != "everything")
            {
                pager = builder.AddTemplate(@"
                    SELECT
                        *
                    FROM
                        (
                            SELECT
                                /**select**/, ROW_NUMBER() OVER(/**orderby**/) AS RowNumber
                            FROM
                                Metadata metadata
                                /**join**/
                                /**leftjoin**/
                                /**where**/
                        ) AS results
                    WHERE
                        RowNumber BETWEEN @start AND @finish
                    ORDER BY
                        RowNumber",
                    new { start = start, finish = finish }
                );
                counter = builder.AddTemplate("SELECT COUNT(*) FROM Metadata metadata /**join**/ /**leftjoin**/ /**where**/");

                builder.Select("metadata.RevisionId AS Id");
                builder.Select("metadata.LastActivity AS LastRun");
                builder.Join("Queries query ON query.Id = metadata.LastQueryId");
                builder.LeftJoin("Users [user] ON metadata.OwnerId = [user].Id");
                builder.Where("metadata.Hidden = 0");

                if (order_by == "featured" || order_by == "recent")
                {
//.........这里部分代码省略.........
开发者ID:glueckkanja,项目名称:stack-exchange-data-explorer,代码行数:101,代码来源:SavedQueryController.cs

示例13: Show


//.........这里部分代码省略.........
                builder.Select("execution.LastRun");
                builder.Select("site.Name AS SiteName");
                builder.Join("QueryExecutions execution ON execution.QueryId = query.Id");
                builder.Join("Sites site ON site.Id = execution.SiteId");
                builder.Join("Revisions ON Revisions.Id = execution.RevisionId AND execution.UserId = @user", new { user = id });
                builder.Join(@"
                    Metadata metadata ON
                    (
                        metadata.RevisionId = Revisions.RootId AND
                        metadata.OwnerId = Revisions.OwnerId
                    ) OR (
                        metadata.RevisionId = Revisions.Id AND
                        metadata.OwnerId = Revisions.OwnerId AND
                        Revisions.RootId IS NULL
                    ) OR (
                        metadata.RevisionId = Revisions.Id AND
                        metadata.OwnerId IS NULL AND
                        Revisions.OwnerId IS NULL
                    )"
                );
                builder.OrderBy("execution.LastRun DESC");

                message = user.Id == CurrentUser.Id ?
                    "You have never ran any queries" : "No queries ran recently";
            }
            else
            {
                builder.Select("metadata.RevisionId AS Id");
                builder.Select("metadata.LastActivity AS LastRun");
                builder.Join("Metadata metadata on metadata.LastQueryId = query.Id");

                if (order_by == "favorite")
                {
                    builder.Join(@"
                        Votes ON
                        Votes.RootId = metadata.RevisionId AND
                        (
                            Votes.OwnerId = metadata.OwnerId OR
                            (Votes.OwnerId IS NULL AND metadata.OwnerID IS NULL)
                        ) AND
                        Votes.UserId = @user AND
                        Votes.VoteTypeId = @vote",
                        new { user = id, vote = (int)VoteType.Favorite }
                    );
                    builder.OrderBy("metadata.Votes DESC");

                    useLatest = true;
                    message = user.Id == CurrentUser.Id ?
                        "You have no favorite queries, click the star icon on a query to favorite it" : "No favorites";
                } else {
                    builder.Where("metadata.OwnerId = @user", new { user = id });
                    builder.Where("metadata.Hidden = 0");
                    builder.OrderBy("metadata.LastActivity DESC");

                    message = user.Id == CurrentUser.Id ?
                        "You haven't edited any queries" : "No queries";
                }
            }

            builder.Select("[user].Id as CreatorId");
            builder.Select("[user].Login as CreatorLogin");
            builder.Select("metadata.Title AS Name");
            builder.Select("metadata.[Description] AS [Description]");
            builder.Select("metadata.Votes AS FavoriteCount");
            builder.Select("metadata.Views AS Views");
            builder.Select("query.QueryBody AS [SQL]");
            builder.LeftJoin("Users [user] ON [user].Id = metadata.OwnerId");

            var queries = Current.DB.Query<QueryExecutionViewData>(
                pager.RawSql,
                pager.Parameters
            ).Select<QueryExecutionViewData, QueryExecutionViewData>(
                (view) =>
                {
                    view.UseLatestLink = useLatest;
                    view.SiteName = (view.SiteName ?? Site.Name).ToLower();

                    return view;
                }
            );
            int total = Current.DB.Query<int>(counter.RawSql, counter.Parameters).First();

            string href = string.Format("/users/{0}/{1}", user.Id, HtmlUtilities.URLFriendly(user.Login)) + "?order_by=" + order_by;

            ViewData["Queries"] = queries;
            ViewData["PageNumbers"] = new PageNumber(
                href + "&page=-1",
                Convert.ToInt32(Math.Ceiling(total / (decimal)pagesize)),
                pagesize.Value,
                page.Value - 1,
                "pager"
            );

            if (!queries.Any())
            {
                ViewData["EmptyMessage"] = message;
            }

            return View(user);
        }
开发者ID:glueckkanja,项目名称:stack-exchange-data-explorer,代码行数:101,代码来源:UserController.cs

示例14: Index

        public ActionResult Index(string sitename, string order_by, string q, int? page, int? pagesize)
        {
            Site site;

            if (!TryGetSite(sitename, out site))
            {
                return site == null ? (ActionResult)PageNotFound() : RedirectPermanent(string.Format("/{0}/queries",
                    site.TinyName.ToLower()
                ));
            }

            Site = site;
            QuerySearchCriteria searchCriteria = new QuerySearchCriteria(q);

            if (string.IsNullOrEmpty(order_by))
            {
                if (searchCriteria.IsValid)
                {
                    order_by = searchCriteria.IsFeatured ? "featured" : "recent";
                }
                else
                {
                    order_by = CurrentUser.DefaultQuerySort ?? "featured";
                }
            }

            if (!searchCriteria.IsValid)
            {
                CurrentUser.DefaultQuerySort = order_by;
            }

            ViewData["Site"] = Site;
            SelectMenuItem("Queries");

            var pagesizeProvided = pagesize.HasValue;

            if (!Current.User.IsAnonymous && !pagesizeProvided)
            {
                pagesize = Current.User.DefaultQueryPageSize;
            }

            pagesize = Math.Max(Math.Min(pagesize ?? 50, 100), 10);
            page = Math.Max(page ?? 1, 1);

            if (!Current.User.IsAnonymous)
            {
                Current.User.DefaultQueryPageSize = pagesize;
            }

            int start = ((page.Value - 1) * pagesize.Value) + 1;
            int finish = page.Value * pagesize.Value;
            var builder = new SqlBuilder();
            SqlBuilder.Template pager = null, counter = null;

            if (order_by != "everything")
            {
                pager = builder.AddTemplate(@"
                    SELECT
                        *
                    FROM    
                        (
                            SELECT
                                /**select**/, ROW_NUMBER() OVER(/**orderby**/) AS RowNumber
                            FROM
                                QuerySets qs
                                /**join**/
                                /**leftjoin**/
                                /**where**/
                        ) AS results
                    WHERE
                        RowNumber BETWEEN @start AND @finish
                    ORDER BY
                        RowNumber",
                    new { start = start, finish = finish }
                );
                counter = builder.AddTemplate("SELECT COUNT(*) FROM QuerySets qs /**join**/ /**leftjoin**/ /**where**/");

                builder.Select("qs.Id as QuerySetId");
                builder.Select("qs.LastActivity AS LastRun");
                builder.Join("Revisions r ON r.Id = qs.CurrentRevisionId");
                builder.Join("Queries q ON q.Id = r.QueryId");
                builder.LeftJoin("Users u ON qs.OwnerId = u.Id");
                builder.Where("qs.Hidden = 0");
                builder.Where("qs.Title is not null");
                builder.Where("qs.Title <> ''");

                if (order_by == "featured" || order_by == "recent")
                {
                    if (order_by == "featured")
                    {
                        builder.Where("qs.Featured = 1");
                        builder.OrderBy("qs.Votes DESC");
                    }

                    builder.OrderBy("qs.LastActivity DESC");
                }
                else
                {
                    int threshold = 0;

//.........这里部分代码省略.........
开发者ID:jtbandes,项目名称:StackExchange.DataExplorer,代码行数:101,代码来源:QuerySetController.cs

示例15: Show

        public ActionResult Show(int id, string name, string order_by, int? page)
        {
            User user = !Current.User.IsAnonymous && Current.User.Id == id ? Current.User : Current.DB.Users.Get(id);

            if (user == null)
            {
                return PageNotFound();
            }

            // if this user has a display name, and the title is missing or does not match, permanently redirect to it
            if (user.UrlTitle.HasValue() && (string.IsNullOrEmpty(name) || name != user.UrlTitle))
            {
                return PageMovedPermanentlyTo(string.Format("/users/{0}/{1}",user.Id, HtmlUtilities.URLFriendly(user.Login)) + Request.Url.Query);
            }

            DataExplorerDatabase db = Current.DB;

            SetHeader(user.Login);
            SelectMenuItem("Users");

            var profileTabs = new SubHeader
            {
                Selected = order_by,
                Items = new List<SubHeaderViewData>
                {
                    new SubHeaderViewData
                    {
                        Description = "edited",
                        Title = "Recently edited queries",
                        Href = "/users/" + user.Id + "?order_by=edited",
                        Default = true,
                    },
                    new SubHeaderViewData
                    {
                        Description = "favorite",
                        Title = "Favorite queries",
                        Href = "/users/" + user.Id + "?order_by=favorite"
                    },
                    new SubHeaderViewData
                    {
                        Description = "recent",
                        Title = "Recently executed queries",
                        Href = "/users/" + user.Id + "?order_by=recent"
                    }
                }
            };
            ViewData["UserQueryHeaders"] = profileTabs;

            page = Math.Max(page ?? 1, 1);
            int? pagesize = 15; // In case we decide to make this a query param

            int start = ((page.Value - 1) * pagesize.Value) + 1;
            int finish = page.Value * pagesize.Value;
            string message;
            var builder = new SqlBuilder();
            var pager = builder.AddTemplate(@"
                SELECT
                    *
                FROM
                    (
                        SELECT
                            /**select**/, ROW_NUMBER() OVER(/**orderby**/) AS RowNumber
                        FROM
                            Queries q
                            /**join**/
                            /**leftjoin**/
                            /**where**/
                    ) AS results
                WHERE
                    RowNumber BETWEEN @start AND @finish
                ORDER BY
                    RowNumber",
                new { start = start, finish = finish }
            );
            var counter = builder.AddTemplate("SELECT COUNT(*) FROM Queries q /**join**/ /**leftjoin**/ /**where**/");

            if (order_by == "recent")
            {
                builder.Select("re.RevisionId AS Id");
                builder.Select("re.LastRun");
                builder.Select("s.Name AS SiteName");
                builder.Where("re.UserId = @user", new { user = id });
                builder.Join("Revisions r ON r.QueryId = q.Id");
                builder.Join("RevisionExecutions re ON re.RevisionId = r.Id");
                builder.Join("Sites s ON s.Id = re.SiteId");
                builder.Join(@"QuerySets qs ON qs.Id = r.OriginalQuerySetId");
                builder.OrderBy("re.LastRun DESC");

                message = user.Id == CurrentUser.Id ?
                    "You have never ran any queries" : "No queries ran recently";
            }
            else
            {
                builder.Select("qs.CurrentRevisionId AS Id");
                builder.Select("qs.LastActivity AS LastRun");
                builder.Join("Revisions r on r.QueryId = q.Id");
                builder.Join("QuerySets qs on qs.CurrentRevisionId = r.Id");

                if (order_by == "favorite")
                {
//.........这里部分代码省略.........
开发者ID:speedsticko,项目名称:DataExplorerPG,代码行数:101,代码来源:UserController.cs


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