-
How to define SqlProvider for this example? public class UserRepository : DapperRepository<User>
{
public UserRepository(IDbConnection connection, ISqlGenerator<User> sqlGenerator)
: base(connection, sqlGenerator)
{
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Solution 1: var sqlGenerator = new SqlGenerator<User>(SqlProvider.MySQL); Solution 2: MicroOrmConfig.SqlProvider = SqlProvider.MySQL; |
Beta Was this translation helpful? Give feedback.
-
@phnx47 thanks for reply, but I'm not getting the solution 1, because i need to define provider by repository e.g; Repository1 uses MSSQL and Repository2 uses MYSQL. Can you help me? |
Beta Was this translation helpful? Give feedback.
-
I can do this in DI and it's working now. Specific repository builder.Services.AddScoped<IUserRepository<User>, UserRepository<User>>(s => new UserRepository<User>(s.GetRequiredService<IDbConnection>(), new SqlGenerator<User>(SqlProvider.MySQL, false))); Generic repository builder.Services.AddScoped<IDapperRepository<Client>, DapperRepository<Client>>(s => new DapperRepository<Client>(s.GetRequiredService<IDbConnection>(), new SqlGenerator<Client>(SqlProvider.MSSQL, false))); tks again. |
Beta Was this translation helpful? Give feedback.
@alexanlp like this: