public async Task GetMultipleBySequence() { var dapper = new DapperImplementor(SqlHelper.GetSqlGenerator()); using (var connection = await _fixture.Factory.ConnectionFactory.CreateAsync()) { var predicate = new GetMultiplePredicate(); predicate.Add <TestEntity>(new FieldPredicate <TestEntity> { Operator = Operator.Gt, PropertyName = "Id", Value = 1 }); predicate.Add <TestEntity>(new FieldPredicate <TestEntity> { Operator = Operator.Eq, PropertyName = "Name", Value = "2" }); var result = dapper.GetMultiple(connection, predicate, null, null); var result1 = result.Read <TestEntity>(); Assert.Equal(2, result1.Count()); var result2 = result.Read <TestEntity>(); Assert.Single(result2); } }
public async Task DeleteWithCustomObject() { var dapper = new DapperImplementor(SqlHelper.GetSqlGenerator()); using (var connection = await _fixture.Factory.ConnectionFactory.CreateAsync()) { dapper.Delete <TestEntity>(connection, new { Id = 1, Name = "1" }, null, null); Assert.Null(await dapper.GetAsync <TestEntity>(connection, 1, null, null)); } }
public RepositoryBase(IDbContextBase dBContext) { DbContext = dBContext; dapperImplementor = new DapperImplementor( new SqlGeneratorImpl( dBContext.GetConfigurationContext <DapperExtensionsConfiguration>()) ); ClassMapper = dapperImplementor.SqlGenerator.Configuration.GetMap(typeof(TEntity)); }
public async Task GetAsyncWithCustomObject() { var dapper = new DapperImplementor(SqlHelper.GetSqlGenerator()); using (var connection = await _fixture.Factory.ConnectionFactory.CreateAsync()) { var result = await dapper.GetAsync <TestEntity>(connection, new { Id = 1 }, null, null); Assert.NotNull(result); } }
public async Task Delete() { var dapper = new DapperImplementor(SqlHelper.GetSqlGenerator()); using (var connection = await _fixture.Factory.ConnectionFactory.CreateAsync()) { dapper.Delete(connection, new TestEntity() { Id = 1 }, null, null); Assert.Null(await dapper.GetAsync <TestEntity>(connection, 1, null, null)); Assert.Throws <ArgumentException>(() => dapper.Delete(connection, new TestClass(), null, null)); } }
public async Task InsertAndGetAsync() { var dapper = new DapperImplementor(SqlHelper.GetSqlGenerator()); using (var connection = await _fixture.Factory.ConnectionFactory.CreateAsync()) { dapper.Insert(connection, new List <TestEntity> { new TestEntity() }, null, null); var result = await dapper.GetAsync <TestEntity>(connection, 1, null, null); Assert.NotNull(result); Assert.Equal(1, result.Id); } }
public async Task DeleteWithPredicate() { var dapper = new DapperImplementor(SqlHelper.GetSqlGenerator()); using (var connection = await _fixture.Factory.ConnectionFactory.CreateAsync()) { var predicate = new FieldPredicate <TestEntity> { Operator = Operator.Eq, PropertyName = "Id", Value = 1 }; dapper.Delete <TestEntity>(connection, predicate, null, null); Assert.Null(await dapper.GetAsync <TestEntity>(connection, 1, null, null)); } }
public async Task Count() { var dapper = new DapperImplementor(SqlHelper.GetSqlGenerator()); using (var connection = await _fixture.Factory.ConnectionFactory.CreateAsync()) { var predicate = new FieldPredicate <TestEntity> { Operator = Operator.Gt, PropertyName = "Id", Value = 1 }; var result = dapper.Count <TestEntity>(connection, predicate, null, null); Assert.Equal(2, result); } }
public async Task GetSet() { var dapper = new DapperImplementor(SqlHelper.GetSqlGenerator()); var sort = new List <ISort>() { Predicates.Sort <TestEntity>(x => x.Id) }; using (var connection = await _fixture.Factory.ConnectionFactory.CreateAsync()) { var result = dapper.GetSet <TestEntity>(connection, null, sort, 1, 2, null, null, true); Assert.Equal(2, result.Count()); Assert.Equal(2, result.First().Id); Assert.Equal(3, result.Last().Id); } }
public EntityQueryBuilder(ISession session) { Guard.ArgumentNotNull(session, nameof(session)); // ReSharper disable once UsePatternMatching var sqlException = session as Session; if (sqlException != null) { var sqlGeneratorImpl = new SqlGeneratorImpl(sqlException.Configuration); _dapperImplementation = new DapperImplementor(sqlGeneratorImpl); } else { throw new InvalidOperationException("ISession is not a Session type."); } _dapperSession = new DapperSession(sqlException.GetConnection()); }
public async Task <IEnumerable <User> > GetByNameOrCpfCnpj(string nameOrCpfCnpj, int page, int resultsPerPage, IDbTransaction transaction = null, int?commandTimeout = null) { try { var predicates = Predicates.Group(GroupOperator.Or, Predicates.Field <User>(u => u.Name, Operator.Like, nameOrCpfCnpj), Predicates.Field <User>(u => u.CpfCnpj, Operator.Like, nameOrCpfCnpj)); IDbConnection conn = null; if (transaction != null) { conn = transaction.Connection; } else { conn = DbContext.Connection; } IList <ISort> sorts = new List <ISort> { Predicates.Sort <User>(u => u.Name), Predicates.Sort <User>(u => u.CpfCnpj) }; IEnumerable <User> result = await Task.Run(() => DapperImplementor.GetPage <User>( conn, predicates, sorts, page, resultsPerPage, transaction, commandTimeout, true)); return(result); } catch (Exception e) { throw e; } }