public void Method_CRUD(DataTable dt, Class clss) { var provider = ConnectionProviderManager.DefaultProvider; TableName tname = new TableName(provider, dt.TableName); SqlMaker gen = new SqlMaker(tname.FormalName) { PrimaryKeys = dt.PrimaryKey.Select(x => x.ColumnName).ToArray() }; foreach (DataColumn column in dt.Columns) { string cname = column.ColumnName; gen.Add(cname, "{" + cname + "}"); } Method method = new Method("Insert") { Modifier = Modifier.Public, Type = new TypeInfo(typeof(string)), }; method.Statement.AppendLine("return $\"" + gen.Insert() + "\";"); clss.Add(method); method = new Method("Update") { Modifier = Modifier.Public, Type = new TypeInfo(typeof(string)), }; method.Statement.AppendLine("return $\"" + gen.Update() + "\";"); clss.Add(method); method = new Method("InsertOrUpdate") { Modifier = Modifier.Public, Type = new TypeInfo(typeof(string)), }; method.Statement.AppendLine("return $\"" + gen.InsertOrUpdate() + "\";"); clss.Add(method); method = new Method("Delete") { Modifier = Modifier.Public, Type = new TypeInfo(typeof(string)), }; method.Statement.AppendLine("return $\"" + gen.Delete() + "\";"); clss.Add(method); }
private void OperateOnSubmit(RowOperation operation, TEntity entity) { SqlMaker gen = this.Generator; var dict = broker.ToDictionary(entity); gen.AddRange(dict); string sql = null; switch (operation) { case RowOperation.Insert: sql = gen.Insert(); break; case RowOperation.Update: sql = gen.Update(); break; case RowOperation.InsertOrUpdate: sql = gen.InsertOrUpdate(); break; case RowOperation.Delete: sql = gen.Delete(); break; } if (sql == null) { return; } Context.CodeBlock.AppendLine <TEntity>(sql); var evt = new RowEvent { TypeName = typeof(TEntity).Name, Operation = operation, Row = gen.ToDictionary(), }; Context.RowEvents.Add(evt); gen.Clear(); }