とASP.NET MVC 3
とRazor view
とValueInjecter
を使用しています。EF 4.1コードとValueInjecterからマッピングするときにDataReaderを開きます
マイビューモデル:
public class ProductViewModel
{
public int Id { get; set; }
public string SKU { get; set; }
public string Name { get; set; }
public ICollection<Specification> Specifications { get; set; }
}
Modelクラス:私は製品のリストを返し、その後、私はビューモデルに各製品をマッピングする必要があり
public class Product : IEntity
{
public int Id { get; set; }
public string SKU { get; set; }
public string Name { get; set; }
public virtual ICollection<Specification> Specifications { get; set; }
}
私のアクションメソッド。
public ActionResult JsonGetProductList()
{
IEnumerable<Product> productList = productService.GetAll();
// Mapping
IList<ProductViewModel> viewModelList = productList.Select(c => new ProductViewModel().InjectFrom(c)).Cast<ProductViewModel>().ToList();
}
それは次のエラーでマッピング部のエラーを与えている:
There is already an open DataReader associated with this Command which must be closed first.
が、私はこれをどのように修正するのでしょうか?
あなたの' GetAll'メソッドはどのように見えますか?内部Linqクエリとは何ですか? –
ToList()を呼び出してみてください。 GetAll()メソッドの最後に – Omu