private static async Task DoBulkInsertIntoRealTableAsync(DemoDbContext ctx) { var customersToInsert = new Customer(Guid.NewGuid(), "First name", "Last name"); await ctx.BulkInsertAsync(new[] { customersToInsert }); var insertedCustomer = await ctx.Customers.FirstAsync(c => c.Id == customersToInsert.Id); Console.WriteLine($"Inserted customer: {insertedCustomer.Id}"); }
private static async Task DoBulkInsertSpecifiedColumnsIntoRealTableAsync(DemoDbContext ctx) { var customersToInsert = new Customer(Guid.NewGuid(), "First name", "Last name"); // only "Id" is sent to the DB // alternative ways to specify the column: // * c => new { c.Id } // * c => c.Id // * new SqlBulkInsertOptions { PropertiesProvider = PropertiesProvider.From<Customer>(c => new { c.Id })} await ctx.BulkInsertAsync(new[] { customersToInsert }, c => new { c.Id, c.FirstName, c.LastName }); var insertedCustomer = await ctx.Customers.FirstAsync(c => c.Id == customersToInsert.Id); Console.WriteLine($"Inserted customer: {insertedCustomer.Id}"); }