public virtual void Create(TEntity entity) { if (entity == null) { throw new ArgumentNullException(); } DomainModelValidator <TDbContext> .Validate(entity, _dbContext, ValidationType.OnCreate); _dbContext.Set <TEntity>().Add(entity); }
public virtual void Update(TEntity entity) { if (entity == null) { throw new ArgumentNullException(); } DomainModelValidator <TDbContext> .Validate(entity, _dbContext, ValidationType.OnUpdate); _dbContext.Set <TEntity>().Attach(entity); _dbContext.Entry <TEntity>(entity).State = EntityState.Modified; }
public virtual void Delete(TEntity entity) { if (entity == null) { throw new ArgumentNullException(); } DomainModelValidator <TDbContext> .Validate(entity, _dbContext, ValidationType.OnDelete); if (_dbContext.Entry <TEntity>(entity).State == EntityState.Detached) { _dbContext.Set <TEntity>().Attach(entity); } _dbContext.Set <TEntity>().Remove(entity); }
static void Main(string[] args) { DataSource dataSource = InitDataSource(); InitValidator(); ClassUnderValidation test = new ClassUnderValidation(1); Other other = new Other(0); //DomainModelValidator<DataSource>.Configure(cfg => { }); //DomainModelValidator<string>.Validate(test, "", ValidationType.OnCreate); try { DomainModelValidator <DataSource> .Validate(other, dataSource, ValidationType.OnCreate); } catch (Exception ex) { int i = 10; //throw; } Console.ReadLine(); }