Пример #1
0
        public static void Main(string[] args)
        {
            var myDto = new MyDto {
                Id = 1, IsDeleted = true
            };

            Spry.Select <MyDto>().Column(_ => myDto.Id).Column(_ => myDto.IsDeleted).From("tt")
            .InnerJoin("table2", "audit").On("c1", "d1")
            .InnerJoin("table3", "audit").On("c2", "d2")
            .InnerJoin("table4", "audit").On("c4", "d2")
            .InSchema("review")
            .Where(_ => myDto.Id).EqualTo(1)
            .AndWhere(_ => myDto.Id).InBetween(1, 10)
            .AndWhere(_ => myDto.Id).GreaterThan(5)
            .Build();

            Spry.InsertInto("tableOne", "review")
            .Value("One", 1)
            .Value(_ => myDto.Id)
            .OutputIdentity()
            .Execute(null);

            Spry.Update("tableOne")
            .Set(_ => myDto.Id)
            .Where <int>("id").EqualTo(1)
            .Execute(null);

            Console.ReadLine();
        }
Пример #2
0
        public int CreateAddress(CustomerAddress address)
        {
            using (var connection = _connectionFactory.CreateConnection())
            {
                address.CustomerAddressId = Spry.InsertInto <CustomerAddress>(CUSTOMER_ADDRESS_TABLE)
                                            .Value(_ => address.CustomerId)
                                            .Value(_ => address.LineOne)
                                            .Value(_ => address.City)
                                            .Value(_ => address.Country)
                                            .Value(_ => address.PostCode)
                                            .ExecuteScalar <int>(connection);

                return(address.CustomerAddressId);
            }
        }
Пример #3
0
        public void Insert_CheckOutputInserted()
        {
            var customer = new Customer
            {
                DateOfBirth = DateTime.Today,
                Name        = "John Doe"
            };

            using (var connection = CreateConnection())
            {
                customer.CustomerId = Spry.InsertInto <Customer>(CUSTOMER_TABLE)
                                      .Value(_ => customer.Name)
                                      .Value(_ => customer.DateOfBirth)
                                      .OutputInserted(_ => customer.CustomerId)
                                      .ExecuteScalar <int>(connection);
            }

            Assert.IsTrue(customer.CustomerId > 0);
        }
Пример #4
0
        public int Create(string name, DateTime dateOfBirth)
        {
            using (var connection = _connectionFactory.CreateConnection())
            {
                var customer = new Customer
                {
                    DateOfBirth = dateOfBirth,
                    Name        = name
                };

                customer.CustomerId = Spry.InsertInto <Customer>(CUSTOMER_TABLE)
                                      .Value(_ => customer.Name)
                                      .Value(_ => customer.DateOfBirth)
                                      .OutputIdentity()
                                      .ExecuteScalar <int>(connection);

                return(customer.CustomerId);
            }
        }