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


C# Database.Query方法代码示例

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


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

示例1: GetRecentContent

        protected IEnumerable<Document> GetRecentContent(DateTime since)
        {
            var db = new Database("umbracoDbDSN");
            var items = db.Query<LogEntry>("select * from umbracoLog where logHeader = 'Save' and Datestamp > @0", since);

            //var logItems = user.UserType.Alias == AdminUserTypeAlias 
            //    ? Log.Instance.GetLogItems(LogTypes.Save, sevenDaysAgo)
            //    : Log.Instance.GetLogItems(user, LogTypes.Save, sevenDaysAgo);

            var recentContent = items
                .Select(item => item.NodeId).Distinct()
                .Select(id =>
                {
                    try
                    {
                        return new Document(id);
                    }
                    catch (ArgumentException)
                    {
                        return null;
                    }
                })
                .Where(d => d != null)
                .OrderByDescending(d => d.UpdateDate)
                .ToList();

            return recentContent;
        } 
开发者ID:OlivierAlbertini,项目名称:workflow-for-dot-net,代码行数:28,代码来源:AllRecentContent.ascx.cs

示例2: Update

        public int Update(Database db)
        {
            // Add column 'characterCount' to the database.
            try
            {
                var parms = new Dictionary<string, string>();
                parms.Add("@TableName", "users");
                parms.Add("@newColumn", "characterCount");
                db.Query("ALTER TABLE @TableName ADD @newColumn NOT NULL DEFAULT ( '0' )", parms);
            }
            catch
            { } //Ignore the database error when adding a column that was already added.

            //Insert meta row into database.
            try
            {
                var data = new Dictionary<string, string>();
                data.Add("version", "100");

                db.Insert("meta", data);
            }
            catch
            { }

            return 100;
        }
开发者ID:Taelia,项目名称:tae-mimicka,代码行数:26,代码来源:Version100.cs

示例3: Basics

    public void Basics()
    {
        string path = Path.GetTempFileName();
        using (var database = new Database(path, "test"))
        {
            database.UnsafeBegin("test");
            database.Update("CREATE TABLE People(id INTEGER PRIMARY KEY, first_name, last_name, city)");

            database.Update("INSERT INTO People VALUES (1, 'joe', 'bob', 'houston')");
            database.Update("INSERT INTO People VALUES (2, 'fred', 'hansen', 'atlanta')");
            database.Update("INSERT INTO People VALUES (3, 'ted', 'bundy', 'houston')");
            database.UnsafeCommit("test");

            string[] header = null;
            List<string[]> rows = new List<string[]>();
            Database.HeaderCallback hc = (h) => {header = h;};
            Database.RowCallback rc = (r) => {rows.Add(r); return true;};

            database.Query("SELECT first_name, last_name FROM People WHERE city='houston'", hc, rc);

            Assert.AreEqual(2, header.Length);
            Assert.AreEqual("first_name", header[0]);
            Assert.AreEqual("last_name", header[1]);

            Assert.AreEqual(2, rows.Count);
            Assert.AreEqual(2, rows[0].Length);
            Assert.AreEqual(2, rows[1].Length);

            rows.Sort((lhs, rhs) => lhs[0].CompareTo(rhs[0]));
            Assert.AreEqual("joe", rows[0][0]);
            Assert.AreEqual("bob", rows[0][1]);
            Assert.AreEqual("ted", rows[1][0]);
            Assert.AreEqual("bundy", rows[1][1]);
        }
    }
开发者ID:andyhebear,项目名称:Continuum,代码行数:35,代码来源:DatabaseTest.cs

示例4: AllTransactions

        public DataTable AllTransactions(Database database)
        {
            string sql = "SELECT id, date, amount, remarks FROM transactions WHERE account_id = :id ORDER BY date ASC";
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add(":id", account.Id);

            return database.Query(sql, parameters);
        }
开发者ID:jsmnlcbls,项目名称:Loanbook,代码行数:8,代码来源:AccountTransactions.cs

示例5: GetAllClasses

 public List<Class> GetAllClasses()
 {
     using (var db = new Database(_connectionName))
     {
         var sql = Sql.Builder.Select("*").From("dbo.Class");
         return db.Query<Class>(sql).ToList();
     }
 }
开发者ID:vbhargav80,项目名称:QuantumTest,代码行数:8,代码来源:Repository.cs

示例6: TestQuery

 public void TestQuery()
 {
     dynamic database = new Database(new DbConnectionStub());
     database.Query("select * from people where name = ? and age > ?", "Bob", 35);
     Assert.AreEqual("select * from people where name = @p0 and age > @p1", DatabaseStub.Sql);
     Assert.AreEqual("Bob", DatabaseStub.Parameters[0]);
     Assert.AreEqual(35, DatabaseStub.Parameters[1]);
 }
开发者ID:jaimedp,项目名称:Simple.Data,代码行数:8,代码来源:DatabaseTest.cs

示例7: GetAllStudents

 public List<Student> GetAllStudents()
 {
     using (var db = new Database(_connectionName))
     {
         var sql = Sql.Builder.Select("*").From("dbo.Student");
         return db.Query<Student>(sql).ToList();
     }
 }
开发者ID:vbhargav80,项目名称:QuantumTest,代码行数:8,代码来源:Repository.cs

示例8: SelectAllProductsDto

        public void SelectAllProductsDto()
        {
            using (var db = new Database(DbConnection))
            {
                var productDtos = db.Query<ProductDto>("SELECT Product_Id as Id, Name FROM Product");

                Assert.AreEqual(3, productDtos.Count());
            }
        }
开发者ID:v0id24,项目名称:ByndyuSoft.Infrastructure,代码行数:9,代码来源:Query.cs

示例9: SetUp

 public void SetUp()
 {
     TestUtils.CreateTestDb();
     var db = new Database(TestUtils.ConnStr);
     using (db.OpenConnection())
     {
         _target = db.Query("SELECT 1 AS Id, 'row 1' AS Name, 'row 1 2' AS Name").AsDisconnected().First();
     }
 }
开发者ID:gimmi,项目名称:adoutils,代码行数:9,代码来源:DisconnectedDataRecordTest.cs

示例10: OnInit

        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);

            this.AddResourceToClientDependency("Moriyama.Workflow.Umbraco6.Web.Workflow.Css.Grid.css", ClientDependencyType.Css);

            SendToWorkflowButton.Text = TheGlobalisationService.GetString("send_selected_content_to_workflow");

            var user = User.GetCurrent();
            var sevenDaysAgo = DateTime.Now.AddDays(-7);

            var db = new Database("umbracoDbDSN");
            var items = user.UserType.Alias == AdminUserTypeAlias
                ? db.Query<LogEntry>("select * from umbracoLog where logHeader = 'Save' and Datestamp > @0", sevenDaysAgo)
                : db.Query<LogEntry>("select * from umbracoLog where logHeader = 'Save' and Datestamp > @0 and userId = @1", sevenDaysAgo, user.Id);

            //var logItems = user.UserType.Alias == AdminUserTypeAlias 
            //    ? Log.Instance.GetLogItems(LogTypes.Save, sevenDaysAgo)
            //    : Log.Instance.GetLogItems(user, LogTypes.Save, sevenDaysAgo);

            var recentContent = items
                .Select(item => item.NodeId).Distinct()
                .Select(id =>
                {
                    try
                    {
                        return new Document(id);
                    }
                    catch (ArgumentException)
                    {
                        return null;
                    }
                })
                .Where(d => d != null)
                .OrderByDescending(d => d.UpdateDate)
                .ToList();

            if (!recentContent.Any()) return;

            MyRecentContentGridView.DataSource = recentContent;
            MyRecentContentGridView.DataBind();
        }
开发者ID:OlivierAlbertini,项目名称:workflow-for-dot-net,代码行数:42,代码来源:RecentContent.ascx.cs

示例11: Load

 public void Load(Database database)
 {
     string sql = "SELECT * FROM accounts WHERE id=:id";
     Dictionary<string, object> parameters = new Dictionary<string, object>();
     parameters.Add(":id", Id);
     DataTable results = database.Query(sql, parameters);
     if (results.Rows.Count == 1)
     {
         name = (string)results.Rows[0]["name"];
         remarks = (string)results.Rows[0]["remarks"];
     }
 }
开发者ID:jsmnlcbls,项目名称:Loanbook,代码行数:12,代码来源:Account.cs

示例12: UpdateMany

        public void UpdateMany()
        {
            using (var db = new Database("TouchpointsWeb"))
            {
                db.Command<UserDeck>(x => x.Insert("[email protected]", "pete", "item1"));
                db.Command<UserDeck>(x => x.Insert("[email protected]", "pete", "item2"));
                db.Command<UserDeck>(x => x.Insert("[email protected]", "pete", "item3"));

                db.Command<UserDeck>(x => x.UserDecks.Update(x.Name.Is("Pete")).Where(x.Email == "[email protected]"));

                var peteDecks = db.Query<UserDeck>(x => x.UserDecks.Where(x.Email == "[email protected]"));
            }
        }
开发者ID:vetraskr,项目名称:Pagan,代码行数:13,代码来源:UserDeck.cs

示例13: BuildReconciles

        public static void BuildReconciles(Database db)
        {
            var reconciles = db.Fetch<int>("select TransactionId from TransactionReconciles");

            var transactions = db.Query<Transaction>().Where(x => !reconciles.Contains(x.TransactionId)).ToList();

            foreach (var transaction in transactions)
            {
                var rec = CategoriseTransaction(transaction);

                db.Insert(rec);
            }
        }
开发者ID:throbbo,项目名称:ImportAccounts,代码行数:13,代码来源:TransactionPersister.cs

示例14: GetName

        /// <summary>
        /// 获取用户名
        /// </summary>
        /// <returns></returns>
        public static string GetName()
        {
            string sql = "SELECT username FROM userinfo WHERE [email protected]";
            SqlParam data = new SqlParam { { "@id", GetId() } };
            Database db = new Database();
            SqlDataReader reader = db.Query(sql, data);
            string name = null;

            if (reader.Read()) {
                name = (string)reader["username"];
            }

            reader.Close();
            db.Close();

            return name;
        }
开发者ID:SwimmingTiger,项目名称:ReportingSystem,代码行数:21,代码来源:User.cs

示例15: Test_Query

        public void Test_Query()
        {
            using (IDatabase db = new Database(@"server=localhost\OSPTTEST;database=EXPRESSLIFE;User ID=sa;Password=3Edcvfr4567ujmnb", DatabaseType.SqlServer2008))
            {
                var p1 = db.Single<Post>("select p.post_id as Id, p.*, ps.* from post p inner join post_status ps on p.post_id = ps.post_id where p.post_id = @0", 1016);
                Assert.AreEqual(p1.Id, 1016);
                
                var ps2 = db.Query<Post, PostStatus>("select p.post_id as Id, p.*, ps.* from post p inner join post_status ps on p.post_id = ps.post_id where p.post_id = @0", 1016);
                var p2 = ps2.SingleOrDefault();
                Assert.AreEqual(p2.Id, 1016);

                var ps3 = db.Fetch<Post, PostStatus>("select p.post_id as Id, p.*, ps.* from post p inner join post_status ps on p.post_id = ps.post_id where p.post_id = @0", 1016);
                var p3 = ps3.SingleOrDefault();
                Assert.AreEqual(p3.Id, 1016);

                Func<Post, PostStatus, Post> map = (p, ps) =>
                {
                    p.Status = ps;
                    return p;
                };

                var ps4 = db.Fetch<Post, PostStatus, Post>
                    (map,
                     "select p.post_id as Id, p.*, ps.* from post p inner join post_status ps on p.post_id = ps.post_id where p.post_id = @0", 1016);
                
                var p4 = ps3.SingleOrDefault();

                Assert.AreEqual(p4.Id, 1016);


                Func<Post, PostStatus, Post> pageMap = (p, ps) =>
                {
                    p.Status = ps;
                    return p;
                };

                var ps5 = db.Page<Post, PostStatus, Post>
                    (pageMap, 3, 3,
                     "select p.post_id as Id, p.*, ps.* from post p inner join post_status ps on p.post_id = ps.post_id where p.post_id > @0", 1016);

                var p5 = ps5.Items;

                Assert.AreEqual(p5.Count, 3);

            }
        }
开发者ID:tu226,项目名称:Eagle,代码行数:46,代码来源:NPocoTests.cs


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