我正在Entity Framework 4.1 code first
使用ASP.NET MVC 3
和Razor view
和ValueInjecter
。
我的视图模型:
public class ProductViewModel
{
public int Id { get; set; }
public string SKU { get; set; }
public string Name { get; set; }
public ICollection<Specification> Specifications { get; set; }
}
型号类:
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.
我将如何解决这个问题?