本文整理汇总了C#中IDbConnection.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnection.GetType方法的具体用法?C# IDbConnection.GetType怎么用?C# IDbConnection.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbConnection
的用法示例。
在下文中一共展示了IDbConnection.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JConnect
public JConnect(IDbConnection connection)
{
this.connection = connection;
commandTimeout = 30;
Type type = connection.GetType();
if (type == typeof(System.Data.Odbc.OdbcConnection))
{
typeOfParameter = ParameterType.QuestionMark;
typeOfVendor = VendorType.Odbc;
}
else if (type == typeof(System.Data.OleDb.OleDbConnection))
{
typeOfParameter = ParameterType.QuestionMark;
typeOfVendor = VendorType.OleDb;
}
else if (type == typeof(System.Data.SqlClient.SqlConnection))
{
typeOfParameter = ParameterType.AtSymbol;
typeOfVendor = VendorType.SqlServer;
GetReturningProc += new GetReturningHandler(SqlServerReturning);
}
else
{
typeOfParameter = ParameterType.Colon;
typeOfVendor = VendorType.Oracle;
GetReturningProc += new GetReturningHandler(OracleReturning);
}
GetTimeStampProc += new GetTimeStampHandler(DefaultGetTimeStampProc);
}
示例2: CloneDbConnection
/// <summary>
/// Clones a new DbConnection supported by this provider.
/// </summary>
/// <param name="connection">The connection to clone.</param>
/// <returns>A new DbConnection.</returns>
public override IDbConnection CloneDbConnection(IDbConnection connection)
{
if (connection == null) throw new ArgumentNullException("connection");
var newConnection = (IDbConnection)System.Activator.CreateInstance(connection.GetType());
newConnection.ConnectionString = connection.ConnectionString;
return newConnection;
}
示例3: ProfiledDbConnection
public ProfiledDbConnection(IDbConnection connection, IDbProfiler profiler, bool autoDisposeConnection=true)
{
var hasConn = connection as IHasDbConnection;
if (hasConn != null) connection = hasConn.DbConnection;
var dbConn = connection as DbConnection;
if (dbConn == null)
throw new ArgumentException(connection.GetType().GetOperationName() + " does not inherit DbConnection");
Init(dbConn, profiler, autoDisposeConnection);
}
示例4: ProfiledDbConnection
public ProfiledDbConnection(IDbConnection connection, IDbProfiler profiler)
{
var hasConn = connection as IHasDbConnection;
if (hasConn != null) connection = hasConn.DbConnection;
var dbConn = connection as DbConnection;
if (dbConn == null)
throw new ArgumentException(connection.GetType().Name + " does not inherit DbConnection");
Init(dbConn, profiler);
}
示例5: CloseConnection
public virtual void CloseConnection(IDbConnection conn)
{
try
{
conn.Close();
}
catch
{
throw new Exception("Could not close " + conn.GetType() + " connection");
}
}
示例6: ReplacePrefixParameter
/// <summary>
/// 根据不同数据库加前缀
/// </summary>
/// <param name="cnn">连接</param>
/// <param name="sql">sql语句</param>
/// <returns>替换后的sql</returns>
public static string ReplacePrefixParameter(IDbConnection cnn, string sql)
{
if (!string.IsNullOrEmpty(sql))
{
if (cnn.GetType().ToString().ToLowerInvariant().Contains("oracle"))
{
sql = sql.Replace('@', ':');
}
}
return sql;
}
示例7: CloseConnection
/// <summary>
/// Closes the <see cref="IDbConnection"/>.
/// </summary>
/// <param name="conn">The <see cref="IDbConnection"/> to clean up.</param>
public virtual void CloseConnection(IDbConnection conn)
{
log.Debug("Closing connection");
try
{
conn.Close();
}
catch (Exception e)
{
throw new ADOException("Could not close " + conn.GetType() + " connection", e);
}
}
示例8: DataBaseObjects
public DataBaseObjects(IDbConnection conn, IEnumerable<ITableFilter> tablesToGenerate,
IEnumerable<ITableFilter> columnsToGenerate)
{
_conn = conn;
var tablefilters= new List<ITableFilter>();
if (_conn.GetType().Name.StartsWith("Npgsql",StringComparison.InvariantCultureIgnoreCase))
{
tablefilters.Add(new PostgresTableFilter());
}
InitPublicTables(tablefilters.Union(tablesToGenerate??new ITableFilter[0]),
columnsToGenerate);
}
示例9: DesignConnection
public DesignConnection(string connectionName, IDbConnection conn)
{
this.properties = new HybridDictionary();
this.modifier = MemberAttributes.Assembly;
if (conn == null)
{
throw new ArgumentNullException("conn");
}
this.name = connectionName;
DbProviderFactory factoryFromType = ProviderManager.GetFactoryFromType(conn.GetType(), ProviderManager.ProviderSupportedClasses.DbConnection);
this.provider = ProviderManager.GetInvariantProviderName(factoryFromType);
this.connectionStringObject = new System.Data.Design.ConnectionString(this.provider, conn.ConnectionString);
}
示例10: GetCollection
private DataTable GetCollection(IDbConnection conn, string colName)
{
var conType = conn.GetType();
var method = conType.GetMethod("GetSchema", new Type[] {typeof(string)});
try {
conn.Open();
var result = method.Invoke(conn, new object[] { colName });
var dt = (DataTable)result;
return dt;
} finally {
conn.Close();
}
}
示例11: GetDatabaseType
public static DatabaseType GetDatabaseType( IDbConnection cn ) {
if (cn is OleDbConnection) {
return DatabaseType.Access;
}
if (cn is SqlConnection) {
return DatabaseType.SqlServer;
}
if (cn.GetType() == MysqlFactory.mySqlConnectionType) {
return DatabaseType.MySql;
}
if (cn is OracleConnection) {
return DatabaseType.Oracle;
}
return DatabaseType.Other;
}
示例12: GetProvider
/// <summary>
/// Gets a dialect provider based on the <see cref="connection"/>
/// </summary>
/// <param name="connection">Connection to get a dialect provider from</param>
public static DbLiteDialectProvider GetProvider(IDbConnection connection)
{
if (connection == null)
throw new ArgumentNullException(nameof(connection));
var connectionType = connection.GetType();
DbLiteDialectProvider provider;
if (!dialectProviders.TryGetValue(connectionType.FullName, out provider))
{
throw new DialectProviderNotRegisteredException($"No dialect provider with the name \"{connectionType.FullName}\" are registered.");
}
return provider;
}
示例13: Get
/// <summary>
/// Provides an IDbParser based on the DB connection type.
/// </summary>
/// <param name="connection"></param>
/// <returns></returns>
public static IDbParser Get(IDbConnection connection)
{
Type typeConnection = connection.GetType();
switch (typeConnection.FullName)
{
case "System.Data.SqlClient.SqlConnection": // MS SQL
case "Npgsql.NpgsqlConnection": // PostgreSQL
case "MySql.Data.MySqlClient.MySqlConnection": // MySQL
case "System.Data.SQLite.SQLiteConnection": // SQLite
return new InformationSchemeSupported();
case "IBM.Data.DB2.iSeries.iDB2Connection":
default:
throw new Exception(String.Format("The provided database connection type '{0}' seems to be an unsupported connection", typeConnection.FullName));
}
}
示例14: GetChanges
public IAnalyzeResult GetChanges(IModelParseResult parsedModel, IDbConnection targetDatabase)
{
// check arguments
if (parsedModel == null) throw new ArgumentNullException("parsedModel");
if (targetDatabase == null) throw new ArgumentNullException("targetDatabase");
if (!(parsedModel is IModel)) throw new Exception("Supplied parsed model does not satify internal requirements!");
AnalyzeResult result = new AnalyzeResult();
try
{
// analyze target database
log.DebugFormat("Analyzing the target database '{0}' found in connection string '{1}', connection type is '{2}'", targetDatabase.Database, targetDatabase.ConnectionString, targetDatabase.GetType().FullName);
Parsers.Database.IDbParser dbParser = Parsers.Database.Factory.Get(targetDatabase);
SchemeDefinition dbDefinition = dbParser.RetrieveSchemeDefinition(targetDatabase);
// compare
IModel referenceModel = parsedModel as IModel;
log.DebugFormat("Reference model: '{0}' ({1} tables)", referenceModel.Description, referenceModel.Scheme.Tables.Count);
foreach (var modelTable in referenceModel.Scheme.Tables)
{
log.DebugFormat("Checking reference table '{0}'", modelTable.Name);
var dbTable = dbDefinition.Tables.FirstOrDefault(t => t.Name == modelTable.Name);
if (dbTable != null)
{
// TODO compare with db table
}
else
{
// TODO add migrationt ask for table creation
}
}
}
catch (Exception ex)
{
log.Error("Analysis failed with exception", ex);
result.AddErrorMessage(ex.Message);
result.Success = false;
}
return result;
}
示例15: IsCompatibleConnection
public override bool IsCompatibleConnection(IDbConnection connection)
{
return typeof(OdbcConnection).IsSameOrParentOf(connection.GetType());
}