public BaseDao() { string connectionString = AccountConfigUtils.sqlConfig; var connection = new MySqlConnection(connectionString); Database = new DapperConnection(connection); }
public static void DropTempTable <TEntity>( this IDapperConnection connection, string tableName, int?commandTimeout = null) { connection.DbConnection.DropTempTable <TEntity>(tableName, connection.Transaction, connection.Dialect, commandTimeout); }
public DapperRepositoryBase(IDapperConfiguration configuration) { Configurationn = configuration; WriteConnection = new MySqlConnection(Configurationn.WriteConnectionString); ReadConnection = new MySqlConnection(Configurationn.ReadConnectionString); Connection = new DapperConnection(WriteConnection, ReadConnection); }
public static void CreateTempTable <TEntity>( this IDapperConnection connection, IEnumerable <TEntity> entities, int?commandTimeout = null) { connection.DbConnection.CreateTempTable(entities, connection.Transaction, connection.Dialect, commandTimeout); }
public BaseDao() { string connectionString = "server=localhost;port=3306;user id=root; password=lyx123456; database=okdata; pooling=true; charset=utf8mb4"; var connection = new MySqlConnection(connectionString); Database = new DapperConnection(connection); }
public DeletionApiController(VolyContext context, IDapperConnection dapper, VSettings settings, ILogger <ConversionApiController> logger) { db = context; this.dapper = dapper; this.settings = settings; log = logger; }
public DapperRepositoryBase(IDapperConfiguration configuration, bool IsOriginalTableName) { Configurationn = configuration; WriteConnection = new MySqlConnection(Configurationn.WriteConnectionString); ReadConnection = new MySqlConnection(Configurationn.ReadConnectionString); SqlMapperExtensions.IsOriginalTableName = IsOriginalTableName; Connection = new DapperConnection(WriteConnection, ReadConnection); }
public static T QuerySingleOrDefault <T>( this IDapperConnection connection, string sql, object param = null, int?commandTimeout = null, CommandType?commandType = null) { return(connection.DbConnection.QuerySingleOrDefault <T>(sql, param, connection.Transaction, commandTimeout, commandType)); }
/// <summary> /// Gets a single entity from the <typeparamref name="TEntity"/> table by it's primary key, or throws an exception if not found /// </summary> /// <example> /// <code> /// <![CDATA[ /// var entity = this.connection.Get<UserEntity>(12); /// ]]> /// </code> /// </example> /// <exception cref="InvalidOperationException">The entity was not found.</exception> public static TEntity Get <TEntity>( this IDapperConnection connection, object id, int?commandTimeout = null) where TEntity : class { Ensure.NotNull(connection, nameof(connection)); return(connection.DbConnection.Get <TEntity>(id, connection.Transaction, connection.Dialect, commandTimeout)); }
/// <summary> /// <para>Deletes all the entities in the <typeparamref name="TEntity"/> table which match the <paramref name="conditions"/>.</para> /// <para>Note: <paramref name="conditions"/> must contain a WHERE clause. Use <see cref="DeleteAll{TEntity}"/> if you want to delete all entities.</para> /// </summary> /// <example> /// <code> /// <![CDATA[ /// this.connection.DeleteRange<UserEntity>("WHERE Name LIKE '%Foo%'"); /// ]]> /// </code> /// </example> /// <returns>The number of deleted entities.</returns> public static SqlCommandResult DeleteRange <TEntity>( this IDapperConnection connection, string conditions, object parameters = null, int?commandTimeout = null) { Ensure.NotNull(connection, nameof(connection)); return(connection.DbConnection.DeleteRange <TEntity>(conditions, parameters, connection.Transaction, connection.Dialect, commandTimeout)); }
/// <summary> /// Deletes the entity in the <typeparamref name="TEntity"/> table which has the <paramref name="id"/>. /// </summary> /// <example> /// <code> /// <![CDATA[ /// this.connection.Delete<UserEntity>(5); /// ]]> /// </code> /// </example> /// <exception cref="AffectedRowCountException">The delete command didn't delete anything, or deleted multiple records.</exception> public static void Delete <TEntity>( this IDapperConnection connection, object id, int?commandTimeout = null, bool?verifyAffectedRowCount = null) { Ensure.NotNull(connection, nameof(connection)); connection.DbConnection.Delete <TEntity>(id, connection.Transaction, connection.Dialect, commandTimeout, verifyAffectedRowCount); }
/// <summary> /// <para> /// Efficiently inserts multiple <paramref name="entities"/> into the database, /// and for each one calls <paramref name="setPrimaryKey"/> allowing the primary key to be recorded. /// </para> /// <para>For performance, it's recommended to always perform this action inside of a transaction.</para> /// </summary> /// <example> /// <code> /// <![CDATA[ /// var entities = new [] /// { /// new User { Name = "Little bobby tables" }, /// new User { Name = "Jimmy" }; /// }; /// /// using (var transaction = this.connection.BeginTransaction()) /// { /// this.connection.InsertRange<User, int>(entities, (e, k) => { e.Id = k; }, transaction); /// /// transaction.Commit(); /// } /// ]]> /// </code> /// </example> public static void InsertRange <TEntity, TPrimaryKey>( this IDapperConnection connection, IEnumerable <TEntity> entities, Action <TEntity, TPrimaryKey> setPrimaryKey, int?commandTimeout = null) { Ensure.NotNull(connection, nameof(connection)); connection.DbConnection.InsertRange(entities, setPrimaryKey, connection.Transaction, connection.Dialect, commandTimeout); }
/// <summary> /// Gets the only matching entity from the <typeparamref name="TEntity"/> table which matches the <paramref name="conditions"/>, /// or throws an <see cref="InvalidOperationException"/> if no entries, or multiple entities match. /// </summary> /// <example> /// <code> /// <![CDATA[ /// var user = this.connection.GetSingle<UserEntity>(new { Age = 18 }); /// ]]> /// </code> /// </example> public static TEntity GetSingle <TEntity>( this IDapperConnection connection, object conditions, int?commandTimeout = null) { Ensure.NotNull(connection, nameof(connection)); return(connection.DbConnection.GetSingle <TEntity>(conditions, connection.Transaction, connection.Dialect, commandTimeout)); }
public static T ExecuteScalar <T>( this IDapperConnection connection, string sql, object param = null, int?commandTimeout = null, CommandType?commandType = null) { return(connection.DbConnection.ExecuteScalar <T>(sql, param, connection.Transaction, commandTimeout, commandType)); }
/// <summary> /// Gets the only matching entity from the <typeparamref name="TEntity"/> table which matches the <paramref name="conditions"/>, /// or the default value if none match. Throws an <see cref="InvalidOperationException"/> if multiple entities match. /// </summary> /// <example> /// <code> /// <![CDATA[ /// var user = this.connection.GetSingleOrDefault<UserEntity>("WHERE Age > @MinAge", new { MinAge = 18 }); /// ]]> /// </code> /// </example> public static TEntity GetSingleOrDefault <TEntity>( this IDapperConnection connection, string conditions, object parameters = null, int?commandTimeout = null) { Ensure.NotNull(connection, nameof(connection)); return(connection.DbConnection.GetSingleOrDefault <TEntity>(conditions, parameters, connection.Transaction, connection.Dialect, commandTimeout)); }
public static IEnumerable <T> Query <T>( this IDapperConnection connection, string sql, object param = null, bool buffered = true, int?commandTimeout = null, CommandType?commandType = null) { return(connection.DbConnection.Query <T>(sql, param, connection.Transaction, buffered, commandTimeout, commandType)); }
/// <summary> /// Gets the first matching entity from the <typeparamref name="TEntity"/> table which matches the <paramref name="conditions"/>, /// or the default value if none match. /// </summary> /// <example> /// <code> /// <![CDATA[ /// var user = this.connection.GetFirstOrDefault<UserEntity>(new { Age = 18 }); /// ]]> /// </code> /// </example> public static TEntity GetFirstOrDefault <TEntity>( this IDapperConnection connection, object conditions, string orderBy, int?commandTimeout = null) where TEntity : class { Ensure.NotNull(connection, nameof(connection)); return(connection.DbConnection.GetFirstOrDefault <TEntity>(conditions, orderBy, connection.Transaction, connection.Dialect, commandTimeout)); }
public void ClearAllData(IDapperConnection connection, int?commandTimeout = null) { if (!(connection.Dialect is ISchemaQueryDialect dialect)) { throw new ArgumentException($"The dialect '{connection.Dialect.Name}' does not support querying the schema and can therefore not be used"); } var ignoredTables = new HashSet <string>(this.IgnoredTables ?? Enumerable.Empty <string>()); var tables = connection.Query <AllTablesQueryResult>(dialect.MakeGetAllTablesStatement()); var relations = connection.Query <TableRelationsQueryResult>(dialect.MakeGetAllRelationsStatement()); var schemaRelations = new SchemaRelations(); foreach (var table in tables) { if (!ignoredTables.Contains(table.Name)) { schemaRelations.AddTable(table.Name); } } foreach (var relation in relations) { schemaRelations.AddRelationship(relation.ReferencedTable, relation.ReferencingTable, relation.ReferencingColumn, relation.RelationIsOptional); } var commands = schemaRelations.GetClearDataCommands(); foreach (var command in commands) { switch (command) { case ClearTableCommand c: { var tableSchema = new TableSchema(c.TableName, ImmutableArray <ColumnSchema> .Empty); var sql = dialect.MakeDeleteRangeStatement(tableSchema, null); connection.Execute(sql, commandTimeout: commandTimeout); break; } case NullColumnCommand c: { var sql = dialect.MakeSetColumnNullStatement(c.TableName, c.ColumnName); connection.Execute(sql, commandTimeout: commandTimeout); break; } default: throw new InvalidOperationException("Unknown sql command: " + command?.GetType()); } } }
/// <summary> /// Gets a collection of entities from the <typeparamref name="TEntity"/> table which match the <paramref name="conditions"/>. /// </summary> /// <example> /// <code> /// <![CDATA[ /// var pageBuilder = new PageIndexPageBuilder(3, 10); /// var users = this.connection.GetPage<UserEntity>(pageBuilder, new { Age = 10 }, "Age DESC"); /// ]]> /// </code> /// </example> public static PagedList <TEntity> GetPage <TEntity>( this IDapperConnection connection, IPageBuilder pageBuilder, object conditions, string orderBy, IDbTransaction transaction = null, IDialect dialect = null, int?commandTimeout = null) { Ensure.NotNull(connection, nameof(connection)); return(connection.DbConnection.GetPage <TEntity>(pageBuilder, conditions, orderBy, connection.Transaction, connection.Dialect, commandTimeout)); }
private static void AddOrdersToCustomer(IDapperConnection dapperConnection, int customerId) { dapperConnection.Execute(BuildInsertOrdersAgainstCustomerSql(customerId)); dapperConnection.Execute(BuildInsertOrdersAgainstCustomerSql(customerId)); dapperConnection.Execute(BuildInsertOrdersAgainstCustomerSql(customerId)); dapperConnection.Execute(BuildInsertOrdersAgainstCustomerSql(customerId)); dapperConnection.Execute(BuildInsertOrdersAgainstCustomerSql(customerId)); dapperConnection.Execute(BuildInsertOrdersAgainstCustomerSql(customerId)); dapperConnection.Execute(BuildInsertOrdersAgainstCustomerSql(customerId)); dapperConnection.Execute(BuildInsertOrdersAgainstCustomerSql(customerId)); dapperConnection.Execute(BuildInsertOrdersAgainstCustomerSql(customerId)); dapperConnection.Execute(BuildInsertOrdersAgainstCustomerSql(customerId)); }
public void Setup() { var configuration = Substitute.For <IAppUserStoreConfig>(); configuration.UserTableDataKey.Returns(UserTableDataKey); configuration.NullableFields.Returns(NullableUserTableFields); configuration.UserTableJoins.Returns(UserTableJoins); Connection = Substitute.For <IDapperConnection>(); LifetimeScope = DiFixture.Container.BeginLifetimeScope(builder => { builder.Register(c => configuration).As <IAppUserStoreConfig>().SingleInstance(); builder.Register(c => Connection).As <IDapperConnection>().SingleInstance(); builder.Register(c => new AppUserStore(c.Resolve <IAppUserStoreConfig>(), c.Resolve <IDapperConnection>())).SingleInstance(); }); }
public AppUserStore(IAppUserStoreConfig configuration, IDapperConnection connection) { _connection = connection; _configuration = configuration; _userPropertyInfos = typeof(AppUser).GetProperties(); _userIdPropertyInfo = _userPropertyInfos.FirstOrDefault(x => x.Name == _configuration.UserTableDataKey.Item2); _userPropertyInfos = _userPropertyInfos.Where(x => x.Name != _configuration.UserTableDataKey.Item2).ToArray(); if (_userIdPropertyInfo == null) { throw new InvalidDbModelCastException(); } if (_userPropertyInfos.Length == 0) { throw new InvalidDbModelCastException(); } }
public PostDetialViewInvorker(IDapperConnection dapperConnection, ILogger <PostDetialViewInvorker> logger) { this._dapperConnection = dapperConnection; this._logger = logger; }
public UserGroupManager(IDapperConnection connection) { _connection = connection; }
public TagPostsViewInvorker(IDapperConnection dapperConnection, ILogger <TagPostsViewInvorker> logger) { this._dapperConnection = dapperConnection; this._logger = logger; }
public MediaQueryController(VolyContext context, IDapperConnection dapper, ILogger <ScannerController> logger) { db = context; this.dapper = dapper; log = logger; }
protected BaseDatabaseHelper(IDapperConnection database) { this.Database = database; }
public GetPostInfoCommandInvorker(ILogger <GetPostInfoCommandInvorker> logger, IDapperConnection dapperConnection) { this._logger = logger; this._dapperConnection = dapperConnection; }
public UpdatePostCommandInvorker(ILogger <UpdatePostCommandInvorker> logger, IDapperConnection dapperConnection) { this._logger = logger; this._dapperConnection = dapperConnection; }
public GetUserInfoCommandInvorker(ILogger <GetUserInfoCommandInvorker> logger, IDapperConnection dapperConnection) { _logger = logger; _dapperConnection = dapperConnection; }