private IQueryable <UdttIntInt> GetQueryableUdtt(TestContext context, IReadOnlyList <UdttIntInt> list) { var parameterName = $"@p_{Guid.NewGuid():n}"; var dt = new DataTable(); dt.Columns.Add(nameof(UdttIntInt.C1), typeof(int)); dt.Columns.Add(nameof(UdttIntInt.C2), typeof(int)); foreach (var item in list) { dt.Rows.Add(item.C1, item.C2); } var parameter = new SqlParameter(parameterName, dt) { SqlDbType = SqlDbType.Structured, TypeName = "dbo.UdttIntInt", }; return(context.Set <UdttIntInt>().FromSqlRaw($@"select * from {parameterName}", parameter)); }
private async Task RunBatchUpdateAsync() { using (var context = new TestContext(ContextUtil.GetOptions())) { //var updateColumns = new List<string> { nameof(Item.Quantity) }; // Adding explicitly PropertyName for update to its default value decimal price = 0; var query = context.Items.Where(a => a.ItemId <= 500 && a.Price >= price); await query.BatchUpdateAsync(new Item { Description = "Updated" } /*, updateColumns*/); await query.BatchUpdateAsync(a => new Item { Name = a.Name + " Concatenated", Quantity = a.Quantity + 100, Price = null }); // example of BatchUpdate value Increment/Decrement query = context.Items.Where(a => a.ItemId <= 500 && a.Price == null); await query.Take(1).BatchUpdateAsync(a => new Item { Name = a.Name + " TOP(1)", Quantity = a.Quantity + 100 }); // example of BatchUpdate with TOP(1) var list = new List <string>() { "Updated" }; var updatedCount = await context.Set <Item>() .TagWith("From: someCallSite in someClassName") // To test parsing Sql with Tag leading comment .Where(a => list.Contains(a.Description)) .BatchUpdateAsync(a => new Item() { TimeUpdated = DateTime.Now }) .ConfigureAwait(false); var newValue = 5; await context.Parents.Where(parent => parent.ParentId == 1) .BatchUpdateAsync(parent => new Parent { Description = parent.Children.Where(child => child.IsEnabled && child.Value == newValue).Sum(child => child.Value).ToString(), Value = newValue }) .ConfigureAwait(false); } }