コード例 #1
0
        protected override void ResetDatabase()
        {
            using (var context = new DbContext().ConnectionStringName("SQLiteTest", new SqliteProvider()))
            {
                context.UseTransaction(true);

                context.Sql("DELETE FROM Entity").Execute();
                context.Sql("DELETE FROM sqlite_sequence WHERE name = @0", "Entity").Execute();

                context.Commit();
            }
        }
コード例 #2
0
        // PUT: api/Customer/5
        public int Put([FromBody] dynamic customer)
        {
            IDbContext Context = new DbContext().ConnectionStringName("Chinook", new SqlServerProvider());

            int rowsAffected = Context.Sql(@"UPDATE Customer SET
                                                    FirstName = @0,
                                                    LastName = @1,
                                                    Address = @2,
                                                    City = @3,
                                                    Country = @4,
                                                    PostalCode = @5,
                                                    Phone = @6,
                                                    Email = @7
                                                WHERE CustomerId = @8;")
                                        .Parameters(
                                            (string)customer.FirstName,
                                            (string)customer.LastName,
                                            (string)customer.Address,
                                            (string)customer.City,
                                            (string)customer.Country,
                                            (string)customer.PostalCode,
                                            (string)customer.Phone,
                                            (string)customer.Email,
                                            (int)customer.CustomerId)
                                        .Execute();

            return (int)customer.CustomerId;
        }
コード例 #3
0
ファイル: SpecialsModel.cs プロジェクト: WPT-KL/Kongliang
 /// <summary>
 /// 根据餐馆Id 得到特价菜数量。
 /// </summary>
 /// <param name="restaurantId"></param>
 /// <returns></returns>
 public static int CountAll(Guid restaurantId)
 {
     using (var context = new DbContext().ConnectionStringName("CrmRstV1", new SqlServerProvider()))
     {
         return context.Sql(" SELECT COUNT(*) FROM Specials ")
             .QuerySingle<int>();
     }
 }
コード例 #4
0
        protected override void SelectFetchEntities(int entityCount)
        {
            using (var context = new DbContext().ConnectionStringName("SQLiteTest", new SqliteProvider()))
            {
                context.UseTransaction(true);

                var results = context.Sql("SELECT * FROM Entity WHERE Id <= @0", entityCount).QueryMany<Entity>();

                context.Commit();
            }
        }
コード例 #5
0
        protected override void SelectSingleEntity(int entityCount)
        {
            using (var context = new DbContext().ConnectionStringName("SQLiteTest", new SqliteProvider()))
            {
                context.UseTransaction(true);

                do
                {
                    // So much for a select by ID method!
                    var entity = context.Sql("SELECT * FROM Entity WHERE Id = @0", entityCount).QuerySingle<Entity>();
                    entityCount--;
                }
                while (entityCount > 0);

                context.Commit();
            }
        }
コード例 #6
0
        // POST: api/Customer
        public int Post([FromBody] dynamic customer)
        {
            IDbContext Context = new DbContext().ConnectionStringName("Chinook", new SqlServerProvider());
            int customerId = Context.Sql(@"INSERT INTO Customer(FirstName, LastName, Address, City, Country,
                                PostalCode, Phone, Email) VALUES(@0, @1, @2, @3, @4, @5, @6, @7);")
                                .Parameters(
                                    (string)customer.FirstName,
                                    (string)customer.LastName,
                                    (string)customer.Address,
                                    (string)customer.City,
                                    (string)customer.Country,
                                    (string)customer.PostalCode,
                                    (string)customer.Phone,
                                    (string)customer.Email)
                                .ExecuteReturnLastId<int>();

            return customerId;
        }
コード例 #7
0
 // GET: api/Customer/5
 public dynamic Get(int id)
 {
     IDbContext Context = new DbContext().ConnectionStringName("Chinook", new SqlServerProvider());
     dynamic customer = Context.Sql("SELECT * FROM Customer WHERE CustomerId = @0", id).QuerySingle<dynamic>();
     return customer;
 }
コード例 #8
0
 // GET: api/Customer
 public IEnumerable<dynamic> Get()
 {
     IDbContext Context = new DbContext().ConnectionStringName("Chinook", new SqlServerProvider());
     IEnumerable<dynamic> customers = Context.Sql("SELECT * FROM Customer").QueryMany<dynamic>();
     return customers;
 }
コード例 #9
0
 // DELETE: api/Customer/5
 public void Delete(int id)
 {
     IDbContext Context = new DbContext().ConnectionStringName("Chinook", new SqlServerProvider());
     int rowsAffected = Context.Sql("DELETE FROM Customer WHERE CustomerId = @0", id).Execute();
 }