这个问题是关于使用https://github.com/maxtoroq/DbExtensions
DbConnection connection = Database.CreateConnection("name=myconx");
var query = SQL.SELECT("u.username").FROM("Users u").WHERE("Id={0}", 1);
IEnumerable<Users> products = connection.Map<Users>(query);
以下代码返回null不知道为什么?
getDbProviderFactory(connection);
这里的定义不知道下一个代码目的:
static readonly Func<DbConnection, DbProviderFactory> getDbProviderFactory =
(Func<DbConnection, DbProviderFactory>)Delegate.CreateDelegate(typeof(Func<DbConnection, DbProviderFactory>), typeof(DbConnection).GetProperty("DbProviderFactory", BindingFlags.Instance | BindingFlags.NonPublic).GetGetMethod(nonPublic: true));
这是我的连接字符串
<add name="myconx" connectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=ES;Initial Catalog=TestDB;Data Source=ITA-PC\SQLR2" providerName="System.Data.OleDb"/>
答案 0 :(得分:1)
问题是OleDbConnection不会覆盖DbProviderFactory属性,这也是OdbcConnection的问题。我会将这些报告为错误。
如果您有源代码,可以尝试这样的事情:
public static DbProviderFactory GetProviderFactory(this DbConnection connection) {
if (connection is OleDbConnection)
return OleDbFactory.Instance;
return getDbProviderFactory(connection);
}