Exemple #1
0
        static void Main(string[] args)
        {
            ICustomerRepository rep = new SqLiteCustomerRepository();
            var customer = new Customer
                {
                    FirstName = "Sergey",
                    LastName = "Maskalik",
                    DateOfBirth = DateTime.Now
                };
            rep.SaveCustomer(customer);

            Customer retrievedCustomer = rep.GetCustomer(customer.Id);
        }
        public void SaveCustomer(Customer customer)
        {
            if (!File.Exists(DbFile))
            {
                CreateDatabase();
            }

            using (var cnn = SimpleDbConnection())
            {
                cnn.Open();
                customer.Id = cnn.Query<long>(
                    @"INSERT INTO Customer
                    ( FirstName, LastName, DateOfBirth ) VALUES
                    ( @FirstName, @LastName, @DateOfBirth );
                    select last_insert_rowid()", customer).First();
            }
        }