public static void UpdateSpecificProperties <TEntity> (TEntity entity, List <string> props) where TEntity : class { var ctx = new AppDbContext2(); var entityType = ctx.Model.GetEntityTypes() .FirstOrDefault(w => w.ClrType.Name == entity.GetType().Name); if (entityType == null) { throw new Exception($"There isn't any matched entity in {ctx.GetType().Name}"); } var properties = entityType.GetProperties().Select(s => s.Name).ToList(); foreach (var prop in props) { if (properties.Contains(prop)) { ctx.Entry(entity).Property(prop).IsModified = true; } } ctx.SaveChanges(); }
public CompanyServiceRepoEF(AppDbContext2 db) { _db = db; }
public ImageController(AppDbContext2 ctx, IWebHostEnvironment hostEnvironment) { _context = ctx; this._hostEnvironment = hostEnvironment; }
public TodoController(AppDbContext2 ctx) { _context = ctx; }
public TransactionController(AppDbContext2 ctx) { _context = ctx; }