public static void DoInsertEntity(bool go = false) { var repository = MySqlRepoFactory.Create <AzProducts>(); AzProducts azProducts = new AzProducts { ProductName2 = "testvalue" }; var resultinsert = repository .Insert() .For(azProducts); if (go) { var rest = resultinsert.Go(); Console.WriteLine($"{rest.ProductID}\t{rest.ProductName2}"); Console.WriteLine(); } Console.WriteLine(resultinsert.Sql()); Console.WriteLine(); // INSERT [dbo].[Products]([ProductName],[SupplierID],[CategoryID],[QuantityPerUnit],[UnitPrice],[UnitsInStock],[UnitsOnOrder],[ReorderLevel],[Discontinued]) // VALUES('testvalue',NULL,NULL,NULL,NULL,NULL,NULL,NULL,0); // SELECT [ProductID],[ProductName] as ProductName2,[SupplierID],[CategoryID],[QuantityPerUnit],[UnitPrice],[UnitsInStock],[UnitsOnOrder],[ReorderLevel],[Discontinued] // FROM [dbo].[Products] // WHERE [ProductID] = SCOPE_IDENTITY(); }
public static void DoDeleteEntity() { var repository = NormalRepoFactory.Create <AzProducts>(); AzProducts azProducts = new AzProducts { ProductName2 = "testvalue", ProductID = 82 }; var resultUpdate = repository.Delete().For(azProducts); Console.WriteLine(resultUpdate.Sql()); Console.WriteLine(); // DELETE [dbo].[Products] WHERE [ProductID] = 82; }
public static void DoDeleteEntity(bool go = false) { var repository = MySqlRepoFactory.Create <AzProducts>(); AzProducts azProducts = new AzProducts { ProductName2 = "testvalue", ProductID = 81 }; var resultUpdate = repository.Delete().For(azProducts); Console.WriteLine(resultUpdate.Sql()); Console.WriteLine(); int result = dbConnection.Execute(resultUpdate.Sql()); Console.WriteLine($"{result}"); }
public static void DoUpdateEntityParam() { var repository = NormalRepoFactory.Create <AzProducts>(); AzProducts azProducts = new AzProducts { ProductName2 = "testvalue", ProductID = 82 }; var resultUpdate = repository.Update().For(azProducts); Console.WriteLine(resultUpdate.ParamSql()); Console.WriteLine(); // UPDATE [dbo].[Products] // SET ProductName = @ProductName2, SupplierID = @SupplierID, CategoryID = @CategoryID, QuantityPerUnit = @QuantityPerUnit, // UnitPrice = @UnitPrice, UnitsInStock = @UnitsInStock, UnitsOnOrder = @UnitsOnOrder, ReorderLevel = @ReorderLevel, Discontinued = @Discontinued // WHERE ProductID = @ProductID; }
public static void DoUpdateEntity() { var repository = NormalRepoFactory.Create <AzProducts>(); AzProducts azProducts = new AzProducts { ProductName2 = "testvalue", ProductID = 82 }; var resultUpdate = repository.Update().For(azProducts); Console.WriteLine(resultUpdate.Sql()); Console.WriteLine(); // UPDATE [dbo].[Products] // SET [ProductName] = 'testvalue', [SupplierID] = NULL, [CategoryID] = NULL, [QuantityPerUnit] = NULL, [UnitPrice] = NULL, // [UnitsInStock] = NULL, [UnitsOnOrder] = NULL, [ReorderLevel] = NULL, [Discontinued] = 0 // WHERE [ProductID] = 82; }
public static void DoInsertEntityParam( ) { var repository = NormalRepoFactory.Create <AzProducts>(); AzProducts azProducts = new AzProducts { ProductName2 = "testvalue" }; var resultinsert = repository .Insert() .For(azProducts); Console.WriteLine(resultinsert.ParamSql()); Console.WriteLine(); // INSERT [dbo].[Products]([ProductName],[SupplierID],[CategoryID],[QuantityPerUnit],[UnitPrice],[UnitsInStock],[UnitsOnOrder],[ReorderLevel],[Discontinued]) // VALUES(@ProductName2,@SupplierID,@CategoryID,@QuantityPerUnit,@UnitPrice,@UnitsInStock,@UnitsOnOrder,@ReorderLevel,@Discontinued); // SELECT [ProductID],[ProductName] as ProductName2,[SupplierID],[CategoryID],[QuantityPerUnit],[UnitPrice],[UnitsInStock],[UnitsOnOrder],[ReorderLevel],[Discontinued] // FROM [dbo].[Products] // WHERE [ProductID] = SCOPE_IDENTITY(); }
public static void DoUpdateEntityParam() { var repository = MySqlRepoFactory.Create <AzProducts>(); var resultUpdate = repository .Update() .ParamSet(p => p.ProductName2, p => p.CategoryID) .Where(p => p.ProductID == p.ProductID); Console.WriteLine(resultUpdate.ParamSql()); Console.WriteLine(); AzProducts products = new AzProducts() { ProductID = 84, ProductName2 = "testvalue100", CategoryID = 7 }; int result = dbConnection.Execute(resultUpdate.ParamSql(), products); Console.WriteLine($"{result}"); }
public static void DoInsertEntityParam() { var repository = MySqlRepoFactory.Create <AzProducts>(); AzProducts azProduct = new AzProducts { ProductName2 = "testvalue" }; var resultinsert = repository .Insert(); Console.WriteLine(resultinsert.ParamSql()); Console.WriteLine(); // 需返回自增字段,所以用Query IEnumerable <AzProducts> azProducts = dbConnection.Query <AzProducts>(resultinsert.ParamSql(), azProduct); foreach (var item in azProducts) { Console.WriteLine($"{item.ProductID}\t{item.ProductName2}"); } }