patterncsharpMinor
Micro ORM on the lines of dapper
Viewed 0 times
microthedapperormlines
Problem
Designing a micro ORM inspired by Dapper. I'm building this as an exercise to learn. I would appreciate if you guys can review my code.
I would also appreciate any suggestions regarding the features that can/should be added to this ORM. The source is available here.
ConnectionStringProvider.cs
ConnectionProvider.cs
```
public interface IConnectionProvider : IDisposable {
DbConnection CreateConnection(string connectionStringKey);
DbDataAdapter Adapter { get; }
IDbDataParameter CreateParameter();
}
public class ConnectionProvider : IConnectionProvider {
IDbConnectionStringProvider _connectionStringProvider;
DbProviderFactory _dbProviderFactory;
DbConnection _dbConnec
I would also appreciate any suggestions regarding the features that can/should be added to this ORM. The source is available here.
ConnectionStringProvider.cs
public interface IDbConnectionStringProvider {
ConnectionStringEntity GetConnectionString(string connectionStringKey);
}
public class ConnectionStringProvider : IDbConnectionStringProvider {
public ConnectionStringEntity GetConnectionString(string connectionStringKey) {
Require.NotNullOrEmptyString(connectionStringKey, @"Connection string cannot be empty.");
Require.NotNull(ConfigurationManager.ConnectionStrings, "Please provide a config file with a connection strings entry");
ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[connectionStringKey];
if (settings == null)
throw new ConfigurationErrorsException(string.Format("Cannot find the connection string: [{0}] in the config file.", connectionStringKey));
if (string.IsNullOrWhiteSpace(settings.ConnectionString) || string.IsNullOrWhiteSpace(settings.ProviderName))
throw new ConfigurationErrorsException(string.Format("Require connection string as well as provider name to instantiate connection for Key [{0}].", connectionStringKey));
return new ConnectionStringEntity() {ConnectionString = settings.ConnectionString, ProviderName = settings.ProviderName};
}
}ConnectionProvider.cs
```
public interface IConnectionProvider : IDisposable {
DbConnection CreateConnection(string connectionStringKey);
DbDataAdapter Adapter { get; }
IDbDataParameter CreateParameter();
}
public class ConnectionProvider : IConnectionProvider {
IDbConnectionStringProvider _connectionStringProvider;
DbProviderFactory _dbProviderFactory;
DbConnection _dbConnec
Solution
Some notes.
- This piece of code
propertyInfo.SetValue(obj, MassageValue(row[column.Name], propertyInfo.PropertyType));will trow exception for nullable types. Did you test it with classes withint?ordouble?properties ?
- Client code with your Tuples are very hard to read ... Look here. As for me, using
Tuplefor public methods is usually bad idea. I would like to have something likeSqlParameterclass there which encapsulates all parameter properties
- I would recommend you to use
Disposeaccording to official recommendations .. . Look here. Section "Basic Dispose pattern". It seems that yourDisposewill work but at least it looks strange ...
Context
StackExchange Code Review Q#138980, answer score: 2
Revisions (0)
No revisions yet.