I want to have method to update only specified properties in my entity. So I created method as below:
public async Task UpdateAsync(string uri, Action<Models.RequestObject> modify, CancellationToken cancellationToken = default)
{
Entities.RequestObject entity = _dbContext.RequestObjects.Local.SingleOrDefault(p => p.Uri == uri)
?? await _dbContext.RequestObjects.AsTracking().Where(p => p.Uri == uri).SingleOrDefaultAsync(cancellationToken);
if (entity != default)
{
Models.RequestObject entityAsModel = entity.ToModel();
modify.Invoke(entityAsModel);
entity = entityAsModel.ToEntity();
await _dbContext.SaveChangesAsync(cancellationToken);
}
}
But this method, due to project architecture, accepts Models.RequestObject
as Action
generic type, but I need to modify Entities.RequestObject
. The code I provided doesn't work. Any ideas why, and how to fix it?