1

这个问题是关于使用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"/>
4

1 回答 1

1

问题是 OleDbConnection 没有覆盖DbProviderFactory属性,这也是 OdbcConnection 的问题。我会将这些报告为错误。

如果你有源代码,你可以尝试这样的事情:

  public static DbProviderFactory GetProviderFactory(this DbConnection connection) {

     if (connection is OleDbConnection)
        return OleDbFactory.Instance;

     return getDbProviderFactory(connection);
  }
于 2013-04-21T17:08:44.580 回答