Код: Выделить всё
[HttpGet]
public async Task GetEntitiesAsync(string? property1, string? property2)
{
var query = _context.Entities.AsNoTracking();
if (property1 != null)
{
query = query.Where(e => e.Property1.Contains(property1));
}
if (property2 != null)
{
query = query.Where(e => e.Property2.Contains(property2));
}
return await query.ToListAsync();
}
Код: Выделить всё
[HttpPatch("{id}")]
public async Task UpdateEntityAsync(int id, Entity entity)
{
var entitiesUpdated = await _context.Entities
.Where(e => e.Id == id)
.ExecuteUpdateAsync(s => s
// How to conditionally chain SetProperty based on
// if entity.Property1 and entity.Property2 are null?
.SetProperty(e => e.Property1, entity.Property1)
.SetProperty(e => e.Property2, entity.Property2)
);
return entitiesUpdated == 1 ? NoContent() : NotFound();
}
Подробнее здесь: https://stackoverflow.com/questions/759 ... cuteupdate
Мобильная версия