2016-07-01 8 views
0

QueryWithRowMapperDelegateで結果セットを返し、クラスの異なるフィールドにマッピングされた列をマッピングしました。以下のコードスニペットは、私のコードと非常によく似ています。これは、返された少量の行でうまく動作しますが、ResultSetが3400+の行で構成される場合、それを繰り返し処理するのに時間がかかります。これは単にこのメソッドを使用する際の制限ですか?QueryWithRowMapperDelegateパフォーマンスの問題 - 代替ソリューション

代替ソリューションはありますか? ResultSetExtractorDelegate<Customer>

List<Customer> customers = Ado.AdoTemplate.QueryWithRowMapperDelegate<Customer>(CommandType.Text, cmdText, 
new RowMapperDelegate<Customer>((reader, rowNum) => 
{ 
    Customer customer = new Customer(); 
    customer.Address = reader.GetString(0, string.Empty); 
    customer.City = reader.GetString(1, string.Empty); 
    customer.CompanyName = reader.GetString(2, string.Empty); 
    customer.ContactName = reader.GetString(3, string.Empty); 
    customer.ContactTitle = reader.GetString(4, string.Empty); 
    customer.Country = reader.GetString(5, string.Empty); 
    customer.Fax = reader.GetString(6, string.Empty); 
    customer.Id = reader.GetString(7, string.Empty); 
    customer.Phone = reader.GetString(8, string.Empty); 
    customer.PostalCode = reader.GetString(9, string.Empty); 
    customer.Region = reader.GetString(10, string.Empty); 
    return customer; 
})).ToList(); 

答えて

0

が委任され、そのためには、プリコンパイルされていません。同じ機能を持つメソッドを作成し、QueryWithRowMapperDelegateに渡します。あなたのCustomerクラスで :

  public static Customer GetFromRecord(IDataReader reader, int rownum) 
     { 
      Customer customer = new Customer(); 
      customer.Address = reader.GetString(0, string.Empty); 
      customer.City = reader.GetString(1, string.Empty); 
      customer.CompanyName = reader.GetString(2, string.Empty); 
      customer.ContactName = reader.GetString(3, string.Empty); 
      customer.ContactTitle = reader.GetString(4, string.Empty); 
      customer.Country = reader.GetString(5, string.Empty); 
      customer.Fax = reader.GetString(6, string.Empty); 
      customer.Id = reader.GetString(7, string.Empty); 
      customer.Phone = reader.GetString(8, string.Empty); 
      customer.PostalCode = reader.GetString(9, string.Empty); 
      customer.Region = reader.GetString(10, string.Empty); 
      return customer; 
     } 

List<Customer> customers = Ado.AdoTemplate.QueryWithRowMapperDelegate<Customer>(CommandType.Text, cmdText, Customer.GetFromRecord).ToList(); 

それははるかに少ない時間で同じ結果を与える必要があります。

よろしく、 ピーター

+0

この大幅に向上、パフォーマンス、おかげで多くの。 – Unrecognized

関連する問題