public CartProxy Find(CartId id) { List<Parameter> parameterList = new List<Parameter>(); string where = "where" + Environment.NewLine ; where += _indent + "Cart.CustomerId = @customerId"; parameterList.Add(new Parameter("customerId", id.CustomerId)); TextBuilder tb = new TextBuilder(_templateSql, new { where = where }); string sql = tb.Generate(); DagentDatabase db = new DagentDatabase(_connection); CartProxy cart = db.Query<CartProxy>(sql, parameterList.ToArray()) .Unique("CustomerId") .Create(row => new CartProxy(row.Get<int>("CustomerId"))) .Each((model, row) => { row.Map(model, x => x.CartItemList, "CartItemNo") .Create(() => new CartItemEntity(row.Get<int>("CustomerId"), row.Get<int>("CartItemNo"))) .Do(); }) .Single(); return cart; }
public void FetchIgnore() { IDagentDatabase database = new DagentDatabase("SQLite"); List <Customer> customers = database.Query <Customer>(@" select * from customers c inner join customerPurchases cp on c.customerId = cp.customerId order by c.customerId, cp.no") .Unique("customerId") .Ignore(x => x.name) .Each((model, row) => row.Map(model, x => x.CustomerPurchases, "no").Ignore(x => x.content).Do()) .List(); foreach (var customer in customers) { Assert.AreEqual(null, customer.name); foreach (var customerPurchase in customer.CustomerPurchases) { Assert.AreEqual(null, customerPurchase.content); } } }
public void FetchPrefixColumName() { IDagentDatabase database = new DagentDatabase("SQLite"); List <Customer> customers = database.Query <Customer>(@" select c.*, cp.customerId as cp_customerId, cp.no as cp_no, cp.content as cp_content from customers c inner join customerPurchases cp on c.customerId = cp.customerId order by c.customerId, cp.no") .Unique("customerId") .Each((model, row) => { row.Map(model, x => x.CustomerPurchases, "cp_customerId").Prefix("cp_").Do(); }) .List(); ValidList(customers); }
public void Single() { IDagentDatabase database = new DagentDatabase("SQLite"); Customer customer = database.Query <Customer>(@" select * from customers c inner join customerPurchases cp on c.customerId = cp.customerId where c.customerId between @fromId and @toId order by c.customerId, cp.no", new Parameter("fromId", 1000), new Parameter("toId", 1999)) .Unique("customerId") .Each((model, row) => row.Map(model, x => x.CustomerPurchases, "no").Do()) .Single(); Assert.AreEqual(true, customer.customerId == 1000); Assert.AreEqual(false, string.IsNullOrEmpty(customer.name)); foreach (var purchase in customer.CustomerPurchases) { Assert.AreEqual(customer.customerId, purchase.customerId); Assert.AreEqual(false, string.IsNullOrEmpty(purchase.content)); } }
public void TextBuilder() { string selectSql = @" select * from Customers Customer where {{condition}}"; TextBuilder textBuilder = new TextBuilder( selectSql, new { condition = "Customer.CustomerId > @CustomerId" } ); string orderSql = @" order by {{sort}}"; textBuilder.Append( orderSql, new { sort = "Customer.Name" } ); string sqlSelectOrder = textBuilder.Generate(); DagentDatabase db = new DagentDatabase("connectionStringName"); List <Customer> customers = db.Query <Customer>(sqlSelectOrder, new { CustomerId = 10 }).List(); }
public void FetchForOneToOneUsedIgnoreCase() { IDagentDatabase database = new DagentDatabase("SQLite"); List <CustomerWithBusiness> customers = database.Query <CustomerWithBusiness>(@" select * from customers c inner join business b on c.businessId = b.businessId inner join customerPurchases cp on c.customerId = cp.customerId order by c.customerId, cp.no") .Unique("customerId") .Each((model, row) => { row.Map(model, x => x.Business, "businessName").IgnoreCase(true).Do(); row.Map(model, x => x.CustomerPurchases, "no").Do(); }) .List(); ValidList(customers); }
public string Generate(string tablenName) { string sql = @" insert into IdManege select @tableName, max(Id) + 1, @guid from IdManege where TableName = @tableName; select Id from IdManege where Guid = @guid "; string guid = Guid.NewGuid().ToString(); DagentDatabase db = new DagentDatabase(_connection); string id = db.Query(sql, new { tableName = tablenName, guid = guid }).Scalar<string>(); if (string.IsNullOrEmpty(id)) { id = "1"; db.ExequteNonQuery(@" delete from IdManege where Guid = @guid; insert into IdManege values(@tableName, @id, @guid) ", new Parameter("tableName", tablenName), new Parameter("id", id), new Parameter("guid", guid)); } return id; }
public void NestedTest() { DagentDatabase db = new DagentDatabase("SQLite"); List <Entity1> entities = db.Query <Entity1>(@" select * from Entity1 left join SubEntity1 on SubEntity1.SubEntity1Id = Entity1.SubEntity1Id left join Entity2 on Entity1.Entity1Id = Entity2.Entity1Id left join SubEntity2 on Entity2.SubEntity2Id = SubEntity2.SubEntity2Id left join Entity3 on Entity2.Entity1Id = Entity3.Entity1Id and Entity2.Entity2Id = Entity3.Entity2Id left join SubEntity3 on Entity3.SubEntity3Id = SubEntity3.SubEntity3Id ") .Create(row => new Entity1(new TestService())) .Unique("Entity1Id") .Each((e1, row) => { row.Map(e1, x => x.SubEntity1, "SubEntity1Id").Do(); row.Map(e1, x => x.Entity2s, "Entity2Id") .Create(() => new Entity2(new TestService())) .Unique("Entity1Id", "Entity2Id") .Each(e2 => { row.Map(e2, x => x.SubEntity2, "SubEntity2Id").Do(); row.Map(e2, x => x.Entity3s, "Entity3Id") .Create(() => new Entity3(new TestService())) .Unique("Entity1Id", "Entity2Id", "Entity3Id") .Each(e3 => { row.Map(e3, x => x.SubEntity3, "SubEntity3Id").Do(); }) .Do(); }) .Do(); }).List(); var list = entities.ToList <Entity1>(); Assert.AreEqual(100, list.Count); }
public void QuerySingle() { DagentDatabase db = new DagentDatabase("connectionStringName"); Customer customer = db.Query <Customer>("Customers", new { CustomerId = 1 }).Single(); customer = db.Query <Customer>("select * from Customers where CustomerId = @CustomerId", new { CustomerId = 1 }).Single(); }
public void Nullable() { IDagentDatabase database = new DagentDatabase("SQLite"); CustomerWithNullableId customer = database.Query <CustomerWithNullableId>("customers", new { customerId = 1 }).Single(); Assert.AreEqual(new Nullable <int>(1), customer.customerId); }
public void Delete(PersonDto personDto) { var connection = _session.GetPort<System.Data.Common.DbConnection>(); DagentDatabase db = new DagentDatabase(connection); db.Command<PersonDto>("Person", "PersonId").Delete(personDto); db.ExequteNonQuery("delete from History where PersonId = @personId", new Parameter("personId", personDto.PersonId)); }
public void Delete(CartEntity cart) { DagentDatabase db = new DagentDatabase(_connection); ICommand<CartEntity> cartCommand = CreateCartCommand(db); cartCommand.Delete(cart); db.ExequteNonQuery("delete from CartItem where CustomerId = @customerId", new Parameter("customerId", cart.Id.CustomerId)); }
public void InsertOrUpdateOrDelete() { Customer customer = new Customer(); customer.customerId = 999999; customer.name = "name_" + customer.customerId.ToString(); IDagentDatabase database = new DagentDatabase("SQLite"); ICommand <Customer> command = database.Command <Customer>("customers", "customerId"); int ret = command.Insert(customer); Assert.AreEqual(1, ret); IQuery <Customer> query = database.Query <Customer>("customers", new { customerId = customer.customerId }); Customer registerdCustomer = query.Single(); Assert.AreEqual(customer.customerId, registerdCustomer.customerId); Assert.AreEqual(customer.name, registerdCustomer.name); customer.name = "update_" + customer.name; ret = command.Update(customer); Assert.AreEqual(1, ret); registerdCustomer = query.Single(); Assert.AreEqual(customer.customerId, registerdCustomer.customerId); Assert.AreEqual(customer.name, registerdCustomer.name); ret = command.AutoMapping(false).Map((row, model) => { row["customerId"] = model.customerId; row["name"] = model.name; row["businessId"] = model.businessId; }) .Update(customer); Assert.AreEqual(1, ret); registerdCustomer = query.Single(); Assert.AreEqual(customer.customerId, registerdCustomer.customerId); Assert.AreEqual(customer.name, registerdCustomer.name); ret = command.Delete(customer); Assert.AreEqual(1, ret); registerdCustomer = query.Single(); Assert.AreEqual(null, registerdCustomer); }
public void QueryPaging() { DagentDatabase db = new DagentDatabase("connectionStringName"); int totalCount = 0; List <Customer> customers = db.Query <Customer>( "select * from Customers where CustomerId > @CustomerId", new { CustomerId = 10 }) .Page(10, 100, out totalCount); }
public void ExecuteReader() { IDagentDatabase database = new DagentDatabase("SQLite"); var command = database.Connection.CreateCommand(); command.CommandText = @" select * from customers c inner join customerPurchases cp on c.customerId = cp.customerId order by c.customerId, cp.no"; command.Connection.Open(); var reader = command.ExecuteReader(); List <Customer> customers = new List <Customer>(); int id = 0; while (reader.Read()) { int currentId = int.Parse(reader["customerId"].ToString()); if (currentId != id) { customers.Add(new Customer { customerId = currentId, name = reader["name"].ToString() }); } if (customers.Last().CustomerPurchases == null) { customers.Last().CustomerPurchases = new List <CustomerPurchase>(); } customers.Last().CustomerPurchases.Add(new CustomerPurchase { customerId = currentId, no = Convert.ToInt16(reader["no"]), content = Convert.ToString(reader["content"]) }); id = currentId; } command.Connection.Close(); ValidList(customers); }
public void ConnectionScope() { DagentDatabase db = new DagentDatabase("connectionStringName"); using (IConnectionScope scope = db.ConnectionScope()) { List <Customer> customers = db.Query <Customer>("Customers").List(); List <CustomerCategory> customerCategories = db.Query <CustomerCategory>("CustomerCategory").List(); } }
public void QueryList() { DagentDatabase db = new DagentDatabase("connectionStringName"); List <Customer> customers = db.Query <Customer>("Customers").List(); customers = db.Query <Customer>( "select * from Customers where CustomerId > @CustomerId", new { CustomerId = 10 }) .List(); }
public void DapperTest() { IDagentDatabase database = new DagentDatabase("SQLite"); var customers = database.Connection.Query <Customer>("select * from customers", null); foreach (var customer in customers) { customer.CustomerPurchases = database.Connection.Query <CustomerPurchase>("select * from customerPurchases where customerId = @customerId", new { customerId = customer.customerId }).ToList(); } ValidList(customers); }
public IEnumerable<PersonDto> GetList(PersonPredicate predicate) { var connection = _session.GetPort<System.Data.Common.DbConnection>(); DagentDatabase db = new DagentDatabase(connection); string sql = _sql; StringBuilder where = new StringBuilder(); int suffix = 1; List<Parameter> parameters = new List<Parameter>(); foreach (KeyValuePair<PersonPredicateItem, object> keyValue in predicate) { if (where.ToString() != string.Empty) { where.Append(predicate.And ? " and " : " or "); where.Append(Environment.NewLine); } string paramName = string.Empty; if (keyValue.Key == PersonPredicateItem.LikeName) { paramName = string.Format("name_{0}", suffix); where.Append(string.Format("Person.Name like @{0}", paramName)); parameters.Add(new Parameter(paramName, keyValue.Value.ToString() + "%")); } else if (keyValue.Key == PersonPredicateItem.City) { paramName = string.Format("city_{0}", suffix); where.Append(string.Format("Person.City = @{0}", paramName)); parameters.Add(new Parameter(paramName, keyValue.Value)); } } if (where.ToString() != string.Empty) { sql = string.Format(sql, "where " + where.ToString()); } IEnumerable<PersonDto> personDtos = db.Query<PersonDto>(sql, parameters.ToArray()) .Unique("PersonId") .Each((dto, rows) => rows.Map(dto, x => x.HistoryList, "PersonId", "HistoryNo").Do()) .EnumerateList(); return personDtos; }
public void Mapping() { DagentDatabase db = new DagentDatabase("connectionStringName"); List <Customer> customers = db.Query <Customer>( "select * from Customers where CustomerId > @CustomerId", new { CustomerId = 10 }) .Each((model, row) => { model.CustomerId = row.Get <int>("CustomerId"); model.Name = row.Get <string>("Name"); }) .List(); }
public void InsertUpdateCreate() { DagentDatabase db = new DagentDatabase("connectionStringName"); Customer customer = new Customer { CustomerId = 1 }; db.Command <Customer>("Customer", "CustomerId").Map((updateRow, model) => { updateRow["Name"] = "Ziba-nyan"; }) .Insert(customer); }
public void FetchEach() { IDagentDatabase database = new DagentDatabase("SQLite"); database.Query(@" select * from customers c inner join customerPurchases cp on c.customerId = cp.customerId order by c.customerId, cp.no") .Each(row => { }) .Execute(); List <Customer> customers = database.Query <Customer>(@" select * from customers c inner join customerPurchases cp on c.customerId = cp.customerId order by c.customerId, cp.no") .Unique("customerId") .Each((model, row) => { CustomerPurchase customerPurchaseModel = new CustomerPurchase { customerId = model.customerId, no = row.Get <int>("no"), content = row.Get <string>("content") }; if (model.CustomerPurchases == null) { model.CustomerPurchases = new List <CustomerPurchase>(); } model.CustomerPurchases.Add(customerPurchaseModel); }) .List(); ValidList(customers); }
public void FetchNotAutoMapping() { IDagentDatabase database = new DagentDatabase("SQLite"); List <CustomerWithBusiness> customers = database.Query <CustomerWithBusiness>(@" select * from customers c inner join business b on c.businessId = b.businessId inner join customerPurchases cp on c.customerId = cp.customerId order by c.customerId, cp.no") .AutoMapping(false) .Unique("customerId") .Each((model, row) => { model.customerId = row.Get <int>("customerId"); model.name = row.Get <string>("name"); model.Business = new Business { BusinessId = row.Get <int>("businessId"), BusinessName = row.Get <string>("businessName") }; CustomerPurchase customerPurchaseModel = new CustomerPurchase { customerId = model.customerId, no = row.Get <int>("no"), content = row.Get <string>("content") }; if (model.CustomerPurchases == null) { model.CustomerPurchases = new List <CustomerPurchase>(); } model.CustomerPurchases.Add(customerPurchaseModel); }) .List(); ValidList(customers); }
public void Fill() { IDagentDatabase database = new DagentDatabase("SQLite"); DataTable dt = new DataTable(); database.Fill(dt, @" select * from customers c inner join customerPurchases cp on c.customerId = cp.customerId order by c.customerId, cp.no"); List <Customer> customers = new List <Customer>(); int id = 0; foreach (DataRow row in dt.Rows) { int currentId = int.Parse(row["customerId"].ToString()); if (currentId != id) { customers.Add(new Customer { customerId = currentId, name = row["name"].ToString() }); } if (customers.Last().CustomerPurchases == null) { customers.Last().CustomerPurchases = new List <CustomerPurchase>(); } customers.Last().CustomerPurchases.Add(new CustomerPurchase { customerId = currentId, no = Convert.ToInt16(row["no"]), content = Convert.ToString(row["content"]) }); id = currentId; } ValidList(customers); }
public PersonDto Find(string personId) { var connection = _session.GetPort<System.Data.Common.DbConnection>(); DagentDatabase db = new DagentDatabase(connection); string sql = string.Format(_sql, "where Person.PersonId = @personId"); PersonDto personDto = db.Query<PersonDto>(sql, new { personId = personId }) .Unique("PersonId") .Each((dto, rows) => rows.Map(dto, x => x.HistoryList, "PersonId", "HistoryNo").Do()) .Single(); return personDto; }
public void NpocoTest() { IDagentDatabase database = new DagentDatabase("SQLite"); NPoco.IDatabase db = new NPoco.Database(database.Connection); //var customers = db.Query<Customer>("select * from customers"); var customers = db.Fetch <Customer>("select * from customers"); foreach (var customer in customers) { customer.CustomerPurchases = db.Fetch <CustomerPurchase>("select * from customerPurchases where customerId = @customerId", new { customerId = customer.customerId }); } ValidList(customers); }
public void DagentTestForIterator() { IDagentDatabase database = new DagentDatabase("SQLite"); var customers = database.Query <Customer>("select * from customers").EnumerateList(); using (var scope = database.ConnectionScope()) { foreach (var customer in customers) { customer.CustomerPurchases = database.Query <CustomerPurchase>("select * from customerPurchases where customerId = @customerId", new { customerId = customer.customerId }).List(); } } ValidList(customers); }
//[TestMethod] public void GetStarted() { DagentDatabase db = new DagentDatabase("connectionStringName"); List <Customer> customers = db.Query <Customer>("select * from Customers where CustomerId > @CustomerId", new { CustomerId = 1000 }).List(); Customer customer = new Customer { CustomerId = 1, Name = "Ziba-nyan" }; db.Command <Customer>("Customers", "CustomerId").Insert(customer); customer.Name = "Buchi-nyan"; db.Command <Customer>("Customers", "CustomerId").Update(customer); db.Command <Customer>("Customers", "CustomerId").Delete(customer); }
public void GetStarted() { IDagentDatabase database = new DagentDatabase("SQLite"); Customer customer = database.Query <Customer>("customers", new { customerId = 1 }).Single(); Assert.AreEqual(1, customer.customerId); List <Customer> customers = database.Query <Customer>("customers").List(); Assert.AreEqual(10000, customers.Count); customers = database.Query <Customer>("select * from customers where customerId > @customerId", new { customerId = 1000 }).List(); Assert.AreEqual(9000, customers.Count); int maxId = database.Query("select max(customerId) from customers").Parameters(new { customerId = 1000 }).Scalar <int>(); Assert.AreEqual(10000, maxId); int count = database.Query("select customerId from customers").Unique("customerId").Count(); Assert.AreEqual(10000, count); customer = new Customer { customerId = maxId + 1, name = "getStarted" }; int rtn = database.Command <Customer>("customers", "customerId").Insert(customer); Assert.AreEqual(1, rtn); rtn = database.Command <Customer>("customers", "customerId").Update(customer); Assert.AreEqual(1, rtn); rtn = database.Command <Customer>("customers", "customerId").Delete(customer); Assert.AreEqual(1, rtn); count = 0; database.Query("customers").Each(row => count++).Execute(); Assert.AreEqual(10000, count); }
public void MappingOneToOne() { DagentDatabase db = new DagentDatabase("connectionStringName"); List <Customer> customers = db.Query <Customer>(@" select * from Customers Customer inner join CustomerCategories Category on Category.CustomerCategoryId = Customer.CustomerCategoryId where Customer.CustomerId > @CustomerId", new { CustomerId = 10 }) .Each((model, row) => { CustomerCategory category = new CustomerCategory(); category.CustomerCategoryId = row.Get <int>("CustomCaregoryId"); category.CategoryName = row.Get <string>("CategoryName"); model.Category = category; }) .List(); customers = db.Query <Customer>(@" select * from Customers Customer inner join CustomerCategories Category on Category.CustomerCategoryId = Customer.CustomerCategoryId where Customer.CustomerId > @CustomerId", new { CustomerId = 10 }) .Each((model, row) => { row.Map(model, x => x.Category).Do(); }) .List(); }
public void FetchForOneToOneByTextBuilder() { TextBuilder textBuilder = new TextBuilder(@" select * from customers c"); textBuilder.Append(@" inner join {{join}} on c.businessId = b.businessId", new { join = "business b" }); textBuilder.Append(@" inner join customerPurchases cp on {{on}} order by {{order}}", new { on = "c.customerId = cp.customerId", order = "c.customerId, cp.no" }); string sql = textBuilder.Generate(); IDagentDatabase database = new DagentDatabase("SQLite"); List <CustomerWithBusiness> customers = database.Query <CustomerWithBusiness>(sql) .Unique("customerId") .Each((model, row) => { row.Map(model, x => x.Business, "businessName").Do(); row.Map(model, x => x.CustomerPurchases, "no").Do(); }) .List(); ValidList(customers); sql = textBuilder.Clear().Generate(); Assert.AreEqual("", sql); }
public void TransactionTest() { string sql = @" delete from customers where customerId = -1; "; DagentDatabase database = new DagentDatabase("SQLite"); using (var scope = database.TransactionScope()) { int rtn1 = database.ExequteNonQuery(sql); Assert.AreEqual(0, rtn1); scope.Complete(); } int rtn2 = database.ExequteNonQuery(sql); Assert.AreEqual(0, rtn2); }
public void TransactionScope() { DagentDatabase db = new DagentDatabase("connectionStringName"); using (ITransactionScope scope = db.TransactionScope()) { Customer customer = new Customer { CustomerId = 1, Name = "Ziba-nyan" }; db.Command <Customer>("Customer", "CustomerId").Insert(customer); scope.Complete(); customer.Name = "Buchi-nyan"; db.Command <Customer>("Customer", "CustomerId").Update(customer); scope.Complete(); } }
//[TestMethod] public void RefreshTestData() { DagentDatabase database = new DagentDatabase("SQLite"); using (ITransactionScope scope = database.TransactionScope()) { database.ExequteNonQuery("delete from customers", null); database.ExequteNonQuery("delete from customerPurchases", null); database.ExequteNonQuery("delete from business", null); int customerNo = 10000; int customerPurchasesNo = 10; int businessNo = 10; int businessId = 1; for (int i = 1; i <= customerNo; i++) { database.ExequteNonQuery(string.Format("insert into customers values ({0}, '{1}', '{2}')", i.ToString(), "name_" + i.ToString(), businessId)); if (businessId == 10) { businessId = 0; } businessId++; for (int j = 1; j <= customerPurchasesNo; j++) { database.ExequteNonQuery(string.Format("insert into customerPurchases values ({0}, {1}, '{2}')", i.ToString(), j.ToString(), "content_" + j.ToString())); } } for (int i = 1; i <= businessNo; i++) { database.ExequteNonQuery(string.Format("insert into business values ({0}, '{1}')", i.ToString(), "business_" + i.ToString())); } scope.Complete(); } }
public void FetchParameters() { IDagentDatabase database = new DagentDatabase("SQLite"); List <Customer> customers = database.Query <Customer>(@" select * from customers c inner join customerPurchases cp on c.customerId = cp.customerId where c.customerId between @fromId and @toId order by c.customerId, cp.no", new Parameter("fromId", 1000), new Parameter("toId", 1999)) .Unique("customerId") .Each((model, row) => row.Map(model, x => x.CustomerPurchases, "no").Do()) .List(); ValidBetweenParameter(customers); }
public void Page() { IDagentDatabase database = new DagentDatabase("SQLite"); int count = 0; List <Customer> customers = database.Query <Customer>(@" select c.*, cp.customerId as cp_customerId, cp.no as cp_no, cp.content as cp_content from customers c inner join customerPurchases cp on c.customerId = cp.customerId order by c.customerId, cp.no") .Unique("customerId") .Each((model, row) => row.Map(model, x => x.CustomerPurchases, "cp_customerId").Prefix("cp_").Do()) .Page(100, 10, out count).ToList(); Assert.AreEqual(10, customers.Count); Assert.AreEqual(10000, count); Assert.AreEqual(1001, customers.First().customerId); Assert.AreEqual(1010, customers.Last().customerId); foreach (var customer in customers) { foreach (var purchase in customer.CustomerPurchases) { Assert.AreEqual(customer.customerId, purchase.customerId); Assert.AreEqual(false, string.IsNullOrEmpty(purchase.content)); } } }
private ICommand<CartEntity> CreateCartCommand(DagentDatabase database) { return database.Command<CartEntity>("Cart", "CustomerId") .Map((row, entity) => { row["CustomerId"] = entity.Id.CustomerId; }); }
public IEnumerable<CartItemReadDto> GetCartItemList(int customerId) { List<Parameter> parameterList = new List<Parameter>(); string where = "where" + Environment.NewLine; where += _indent + "Cart.CustomerId = @customerId"; parameterList.Add(new Parameter("customerId", customerId)); TextBuilder tb = new TextBuilder(_templateSql, new { where = where }); string sql = tb.Generate(); DagentDatabase db = new DagentDatabase(_connection); IEnumerable<CartItemReadDto> list = db.Query<CartItemReadDto>(sql, parameterList.ToArray()).EnumerateList(); return list; }
private ICommand<CartItemEntity> CreateCartItemCommand(DagentDatabase database) { return database.Command<CartItemEntity>("CartItem", "CustomerId", "CartItemNo") .Map((row, entity) => { row["CustomerId"] = entity.Id.CartId.CustomerId; row["CartItemNo"] = entity.Id.CartItemNo; }); }
public void Update(CartEntity cart) { DagentDatabase db = new DagentDatabase(_connection); ICommand<CartEntity> cartCommand = CreateCartCommand(db); cartCommand.Update(cart); ICommand<CartItemEntity> cartItemCommand = CreateCartItemCommand(db); foreach (CartItemEntity cartItem in cart.CartItemList) { cartItemCommand.Update(cartItem); } }
public IEnumerable<PersonViewDto> GetViewList() { var connection = _session.GetPort<System.Data.Common.DbConnection>(); DagentDatabase db = new DagentDatabase(connection); string sql = string.Format(_sql, string.Empty); IEnumerable<PersonViewDto> personDtos = db.Query<PersonViewDto>(sql).EnumerateList(); return personDtos; }
public void Insert(PersonDto personDto) { var connection = _session.GetPort<System.Data.Common.DbConnection>(); DagentDatabase db = new DagentDatabase(connection); db.Command<PersonDto>("Person", "PersonId").Insert(personDto); foreach (HistoryDto historyDto in personDto.HistoryList) { db.Command<HistoryDto>("History", "PersonId", "HistoryNo").Insert(historyDto); } }
public void Update(PersonDto personDto) { var connection = _session.GetPort<System.Data.Common.DbConnection>(); DagentDatabase db = new DagentDatabase(connection); db.Command<PersonDto>("Person", "PersonId").Update(personDto); db.ExequteNonQuery("delete from History where PersonId = @personId", new Parameter("personId", personDto.PersonId)); foreach (HistoryDto historyDto in personDto.HistoryList) { db.Command<HistoryDto>("History", "PersonId", "HistoryNo").Insert(historyDto); } }