[英]EntityCommandExecutionException occures when loading embedded entity
I have a code that gets all products from my DB: 我有一个代码可以从数据库中获取所有产品:
using (var entities = new DataEntities())
{
var products = entities.Products.AsQueryable();
if (!string.IsNullOrEmpty(nameFilter))
{
products = products.Where(o => o.Name.Contains(nameFilter));
}
var result = products.Select(ProductBuilder.CreateProductDto);
return result.ToList();
}
CreateProductDto method: CreateProductDto方法:
public static ProductDto CreateProductDto(this Product product)
{
return new ProductDto
{
Id = product.Id,
Name = product.Name,
IsEnabled = product.IsEnabled,
KeyPairDto = new KeyPairDto()
{
Id = product.KeyPair.Id,
EncryptedPrivateExponent = product.KeyPair.EncryptedPrivateExponent,
Modulus = product.KeyPair.Modulus,
PublicExponent = product.KeyPair.PublicExponent,
},
};
}
It works fine on my colleaugue's machine. 在我的同事的机器上工作正常。 But I get EntityCommandExecutionException with the folloing inner exception: There is already an open DataReader associated with this Command which must be closed first.
但是我收到带有以下内部异常的EntityCommandExecutionException: 已经存在与此Command关联的打开的DataReader,必须首先将其关闭。 when trying to access
product.KeyPair
. 尝试访问
product.KeyPair
。
Interesting thing is that if I refresh product.KeyPair
via Debugger - it loads fine. 有趣的是,如果我通过Debugger刷新
product.KeyPair
它加载正常。
Add 加
MultipleActiveResultSets=true
to the provider part of the connection string within your entity framework connection string (ie the part the defines the data source, initial catalog, etc) 到实体框架连接字符串中的连接字符串的提供者部分(即定义数据源,初始目录等的部分)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.