Exemplo n.º 1
0
 public EFRepository(Microsoft.EntityFrameworkCore.DbContext dbContext)
 {
     if (dbContext == null)
     {
         throw new ArgumentNullException("dbContext");
     }
     DbContext = dbContext;
     DbSet     = DbContext.Set <T>();
 }
Exemplo n.º 2
0
        public EfRepository(Microsoft.EntityFrameworkCore.DbContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            _context = context;
            _set     = _context.Set <TEnity>();
        }
Exemplo n.º 3
0
 public void Delete(T t)
 {
     if (t is SoftDeletable deletable)
     {
         deletable.IsDeleted = true;
         _prandoDbContext.Update(deletable);
     }
     else
     {
         _prandoDbContext.Set <T>().Remove(t);
     }
 }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
        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()));
        }
Exemplo n.º 6
0
 public GenericRepository(Microsoft.EntityFrameworkCore.DbContext context)
 {
     this.Context = context;
     this.DbSet   = context.Set <T>();
 }
Exemplo n.º 7
0
 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());
            }
        }
Exemplo n.º 9
0
 public GenericRepository(DbContext context)
 {
     this.Context = context;
     this.DbSet   = context.Set <TE>();
 }
Exemplo n.º 10
0
 public TEntity Get(int Id)
 {
     return(m_context?.Set <TEntity>().Find(Id));
 }
Exemplo n.º 11
0
 public Repository(Microsoft.EntityFrameworkCore.DbContext context)
 {
     m_context  = context;
     m_entities = m_context.Set <TEntity>();
 }
Exemplo n.º 12
0
 public async Task AddAsync(TEntity entity)
 {
     await context.Set <TEntity>().AddAsync(entity);
 }
Exemplo n.º 13
0
 public Repository(Microsoft.EntityFrameworkCore.DbContext dbContext)
 {
     _dbContext  = dbContext ?? throw new ArgumentNullException();
     ModelDbSets = _dbContext.Set <TModel>();
 }
Exemplo n.º 14
0
        public async Task <Maybe <Company> > FindCompanyByCouponAsync(Coupon coupon)
        {
            var res = await _context.Set <Coupon>().FindAsync(coupon);

            return(res.Company);
        }
Exemplo n.º 15
0
 public CompanyRepository(Microsoft.EntityFrameworkCore.DbContext dbContext)
 {
     _context   = dbContext;
     _companies = _context.Set <Company>();
 }
Exemplo n.º 16
0
 public BaseRepository(Microsoft.EntityFrameworkCore.DbContext context)
 {
     Context  = context;
     Entities = Context.Set <TEntity>();
 }
Exemplo n.º 17
0
 public async Task <TEntity> GetAsync(int Id)
 {
     return(await m_context.Set <TEntity>().FindAsync(Id));
 }
Exemplo n.º 18
0
 public void Add(T entity)
 {
     Context.Set <T>().Add(entity);
 }
Exemplo n.º 19
0
 public Repository(Microsoft.EntityFrameworkCore.DbContext dataContext)
 {
     DbSet = dataContext.Set <T>();
 }
Exemplo n.º 20
0
 public TEntity Get(int id)
 {
     return(Context.Set <TEntity>().Find(id));
 }