Below is currently that i use to update the data (more than 1 record) by using EF core. How can update certain column(s) (in this case, actually I just want update CurrencyCode and UpdatedDate columns only)? Now, the only way is, reassign the value in order to update again. But this approach is not suitable if have a lot of columns.
var sorting = await _context.Media.AsNoTracking().ToListAsync();
var redirect = await _context.Website.Where(x => x.url.Equals(url)).AsNoTracking().ToListAsync();
var data = (from sortingData in sorting
join redirectData in redirect on sortingData.MediaID equals redirectData.ID
select new Media
{
ID = sortingData.ID,
Post = sortingData.Post,
CurrencyCode = currencyCode,
CreatedDate = sortingData.CreatedDate,
UpdatedDate = DateTime.Now
}).ToList();
if (data?.Count > 0) //May have more than 1 record.
{
_context.Media.UpdateRange(data);
return await _context.SaveChangesAsync() > 0;
}