I have update a generic update method as follows
public virtual void Update<TEntity>(TEntity entity, string modifiedBy =
null) where TEntity : class,IEntity
{
using (var context = new BanyanDbContext())
{
entity.ModifiedDate = DateTime.UtcNow;
entity.ModifiedBy = modifiedBy;
var existingEntiy = context.Set<TEntity>().Find(entity.Id);
context.Entry(existingEntiy).CurrentValues.SetValues(entity);
context.Entry(existingEntiy).State = EntityState.Modified;
Save(context);
}
}
This method is working fine for updating non reference type values, but CurrentValues.SetValues()
does not set or update navigation properties.
How can I set navigation property in this scenario.