private static void BeforeSaveChangesWithHistory(IEntityFrameworkDbContext dbContext) { DateTime dateTime = DateTime.UtcNow; IModificationHistory entity; EntityState entityState; foreach (var history in dbContext.ChangeTracker.Entries() .Where(e => e.Entity is IModificationHistory && (e.State == EntityState.Added || e.State == EntityState.Modified)) .Select(e => new { Entity = e.Entity as IModificationHistory, e.State })) { entity = history.Entity; entityState = history.State; if (entityState == EntityState.Modified) { dbContext.Entry(entity).Property(e => e.DateCreated).IsModified = false; } if (entityState == EntityState.Added) { entity.DateCreated = dateTime; } entity.DateModified = dateTime; } }
public SqlRepositoryEntityFrameworkDisconnected(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper, IDataAccessStrategy <T> dataAccessStrategy) : base(ctx, logger, mapper) { this.dataAccessStrategy = dataAccessStrategy; }
private static void AfterSaveChangesWithHistory(IEntityFrameworkDbContext dbContext) { foreach (var history in dbContext.ChangeTracker.Entries() .Where(e => e.Entity is IModificationHistory) .Select(e => e.Entity as IModificationHistory)) { history.IsDirty = false; } }
protected UnitOfWork(IRepositoryProvider repositoryProvider, IEntityFrameworkDbContext dbContext) { //CreateDbContext(); RepositoryProvider = repositoryProvider; repositoryProvider.DbContext = dbContext; this.dbContext = dbContext; PrepareDbContext(); }
public static async Task <int> SaveChangesWithModificationHistoryAsync(this IEntityFrameworkDbContext dbContext) { BeforeSaveChangesWithHistory(dbContext); int result = await dbContext.SaveChangesAsync(); AfterSaveChangesWithHistory(dbContext); return(result); }
public static int SaveChangesWithModificationHistory(this IEntityFrameworkDbContext dbContext) { BeforeSaveChangesWithHistory(dbContext); int result = dbContext.SaveChanges(); AfterSaveChangesWithHistory(dbContext); return(result); }
public DictionaryRepository(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper) : base(ctx, logger, mapper) { }
public SqlRepositoryEntityFrameworkAsync(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper) : base(ctx, logger, mapper) { }
protected UnitOfWork2(IEntityFrameworkDbContext context) { this.context = context; PrepareDbContext(); }
public PreSaleOrderDataAccess(IEntityFrameworkDbContext context, bool isNoTracking = true) : base(context, isNoTracking) { }
public static DataTable DataTable(this IEntityFrameworkDbContext context, string query) { return(SqlUtils.GetDataTable(query, context.Database.Connection)); }
public SqlRepositoryEntityFrameworkDisconnected(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper) : base(ctx, logger, mapper) { dataAccessStrategy = ServiceLocator.Current.GetInstance <IDataAccessStrategy <T> >(); }
/// <summary> /// /Initializes a new instance of the <see cref="AuthorizationDataProvider"/> class. /// </summary> /// <param name="logger"> /// The logger. /// </param> /// <param name="connectionString"> /// The Database context. /// </param> public UserDataProvider(ILogger logger, IEntityFrameworkDbContext entityFrameworkDbContext, IHelpers helpers) { this._logger = logger; this._entityFrameworkDbContext = entityFrameworkDbContext; this._helpers = helpers; }
/// <summary>Make a repository of type T.</summary> /// <typeparam name="T">Type of repository to make.</typeparam> /// <param name="dbContext"> /// The <see cref="DbContext"/> with which to initialize the repository. /// </param> /// <param name="factory"> /// Factory with <see cref="DbContext"/> argument. Used to make the repository. /// If null, gets factory from <see cref="_repositoryFactories"/>. /// </param> /// <returns></returns> protected virtual T MakeRepository <T>(Func <IEntityFrameworkDbContext, ILogger, IMapper, object> factory, IEntityFrameworkDbContext dbContext, ILogger logger, IMapper mapper) { var f = factory ?? _repositoryFactories.GetRepositoryFactory <T>() ?? _repositoryFactories.GetDefaultRepositoryFactory <T>(); if (f == null) { throw new NotImplementedException("No factory for repository type, " + typeof(T).FullName); } var repo = (T)f(dbContext, logger, mapper); Repositories[typeof(T)] = repo; return(repo); }
public TicketRepository(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper, IDataAccessStrategy <Ticket> strategy) : base(ctx, logger, mapper, strategy) { }
public LogRepo(IEntityFrameworkDbContext ctx) : base(ctx, null, null) { }
public static bool ExistsLocal <T>(this IEntityFrameworkDbContext dbContext, T entity) where T : class { return(dbContext.Set <T>().Local.Contains(entity)); }
private static DbContext GetDbContext(this IEntityFrameworkDbContext context) => (context as DbContext);
public EmployeeRepository(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper) : base(ctx, logger, mapper) { }
public SqlRepositoryEntityFramework(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper) : base(ctx, logger) { this.ctx = ctx; this.mapper = mapper; set = this.ctx.Set <T>(); }
public ContrahentRepository(IEntityFrameworkDbContext ctx, ILogger logger, IMapper mapper) : base(ctx, logger, mapper) { }
public static T FirstOrDefautLocal <T>(this IEntityFrameworkDbContext dbContext, Func <T, bool> predicate) where T : class { return(dbContext.Set <T>().Local.FirstOrDefault(predicate)); }
public TaskManagerUow(IRepositoryProvider repositoryProvider, IEntityFrameworkDbContext dbContext) : base(repositoryProvider, dbContext) { }
public AddressDataAccess(IEntityFrameworkDbContext context, bool isNoTracking = true) : base(context, isNoTracking) { }
public EntityFrameworkRepository(IEntityFrameworkDbContext dbcontext, IUnitOfWork unitOfWork) : base(unitOfWork) { dbContext = dbcontext; }
public static string GetQuery <T>(this IEntityFrameworkDbContext context) where T : class { return(context.GetDbContext().GetQuery <T>()); }
public GenericRepository(IEntityFrameworkDbContext context, bool isNoTracking = true) { this.context = context; this.isNoTracking = isNoTracking; }
public static bool ExistsLocal <T>(this IEntityFrameworkDbContext dbContext, Func <T, bool> predicate) where T : class { return(dbContext.Set <T>().Local.Any(predicate)); }