public EFRepository(Microsoft.EntityFrameworkCore.DbContext dbContext) { if (dbContext == null) { throw new ArgumentNullException("dbContext"); } DbContext = dbContext; DbSet = DbContext.Set <T>(); }
public EfRepository(Microsoft.EntityFrameworkCore.DbContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } _context = context; _set = _context.Set <TEnity>(); }
public void Delete(T t) { if (t is SoftDeletable deletable) { deletable.IsDeleted = true; _prandoDbContext.Update(deletable); } else { _prandoDbContext.Set <T>().Remove(t); } }
public object GetTestProducts() { //TEST VERSION //ITS WRONG var data = _db.Set <DataAccess.Entities.Product>().Include(x => x.Category).ToList(); return(data); // .Include(x => x.Category).Select(x => new //{ // x.Name, // x.CaloriesValue, // x.Fats, // x.Protein, // x.PhotoUrl, // Category = x.Category.Name //}).ToList(); }
public IQueryable <T> StoredProcedure <T>(params SqlParameter[] parameters) where T : class { var annotation = _dbContext.Model.GetEntityType <T>().FindAnnotation(StoredProcAnnotationName); if (!(annotation?.Value is string)) { throw new InvalidOperationException($"'{typeof(T).Name}' is not a stored procedure result type."); } var spName = annotation.Value.ToString(); var dbSet = _dbContext.Set <T>().AsNoTracking(); if (parameters is null || parameters.Length == 0) { return(dbSet.FromSql(new RawSqlString(spName))); } var prms = string.Join(" ", parameters.Select(x => x.ParameterName)); return(dbSet.FromSql(new RawSqlString($"{spName} {prms}"), parameters.Cast <object>().ToArray())); }
public GenericRepository(Microsoft.EntityFrameworkCore.DbContext context) { this.Context = context; this.DbSet = context.Set <T>(); }
public CouponsRepository(Microsoft.EntityFrameworkCore.DbContext dbContext) { _context = dbContext; _coupons = _context.Set <Coupon>(); }
public async Task Can_add_update_delete_end_to_end_using_partial_shadow_state() { var model = new Model(); var customerType = model.AddEntityType(typeof(Customer)); var property1 = customerType.AddProperty("Id", typeof(int)); customerType.GetOrSetPrimaryKey(property1); customerType.AddProperty("Name", typeof(string)); var optionsBuilder = new DbContextOptionsBuilder() .UseModel(model) .UseInMemoryDatabase(nameof(ShadowStateUpdateTest)) .UseInternalServiceProvider(_fixture.ServiceProvider); var customer = new Customer { Id = 42 }; using (var context = new DbContext(optionsBuilder.Options)) { context.Add(customer); context.Entry(customer).Property("Name").CurrentValue = "Daenerys"; await context.SaveChangesAsync(); context.Entry(customer).Property("Name").CurrentValue = "Changed!"; } using (var context = new DbContext(optionsBuilder.Options)) { var customerFromStore = context.Set <Customer>().Single(); Assert.Equal(42, customerFromStore.Id); Assert.Equal( "Daenerys", (string)context.Entry(customerFromStore).Property("Name").CurrentValue); } using (var context = new DbContext(optionsBuilder.Options)) { var customerEntry = context.Entry(customer).GetInfrastructure(); customerEntry[customerType.FindProperty("Name")] = "Daenerys Targaryen"; context.Update(customer); await context.SaveChangesAsync(); } using (var context = new DbContext(optionsBuilder.Options)) { var customerFromStore = context.Set <Customer>().Single(); Assert.Equal(42, customerFromStore.Id); Assert.Equal( "Daenerys Targaryen", (string)context.Entry(customerFromStore).Property("Name").CurrentValue); } using (var context = new DbContext(optionsBuilder.Options)) { context.Remove(customer); await context.SaveChangesAsync(); } using (var context = new DbContext(optionsBuilder.Options)) { Assert.Equal(0, context.Set <Customer>().Count()); } }
public GenericRepository(DbContext context) { this.Context = context; this.DbSet = context.Set <TE>(); }
public TEntity Get(int Id) { return(m_context?.Set <TEntity>().Find(Id)); }
public Repository(Microsoft.EntityFrameworkCore.DbContext context) { m_context = context; m_entities = m_context.Set <TEntity>(); }
public async Task AddAsync(TEntity entity) { await context.Set <TEntity>().AddAsync(entity); }
public Repository(Microsoft.EntityFrameworkCore.DbContext dbContext) { _dbContext = dbContext ?? throw new ArgumentNullException(); ModelDbSets = _dbContext.Set <TModel>(); }
public async Task <Maybe <Company> > FindCompanyByCouponAsync(Coupon coupon) { var res = await _context.Set <Coupon>().FindAsync(coupon); return(res.Company); }
public CompanyRepository(Microsoft.EntityFrameworkCore.DbContext dbContext) { _context = dbContext; _companies = _context.Set <Company>(); }
public BaseRepository(Microsoft.EntityFrameworkCore.DbContext context) { Context = context; Entities = Context.Set <TEntity>(); }
public async Task <TEntity> GetAsync(int Id) { return(await m_context.Set <TEntity>().FindAsync(Id)); }
public void Add(T entity) { Context.Set <T>().Add(entity); }
public Repository(Microsoft.EntityFrameworkCore.DbContext dataContext) { DbSet = dataContext.Set <T>(); }
public TEntity Get(int id) { return(Context.Set <TEntity>().Find(id)); }