简体   繁体   English

加载嵌入式实体时发生E​​ntityCommandExecutionException

[英]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.

相关问题 ASP .NET实体:EntityCommandExecutionException - ASP .NET Entity: EntityCommandExecutionException 返回PagedList时的EntityCommandExecutionException - EntityCommandExecutionException when returning a PagedList 使用多个Include()与嵌套的Select()时的EntityCommandExecutionException - EntityCommandExecutionException when using multiple Include() with nested Select() System.Data.Entity.Core.EntityCommandExecutionException不由查询中的用户代码处理 - System.Data.Entity.Core.EntityCommandExecutionException Not handled by user code in query 我的身份验证控制器中的System.Data.Entity.Core.EntityCommandExecutionException - System.Data.Entity.Core.EntityCommandExecutionException in my Authentication controller ASP.NET MVC System.Data.Entity.Core.EntityCommandExecutionException - ASP.NET MVC System.Data.Entity.Core.EntityCommandExecutionException Linq Query中的“System.Data.Entity.Core.EntityCommandExecutionException” - 'System.Data.Entity.Core.EntityCommandExecutionException' in Linq Query 在 OK 方法 OData 中发生时捕获错误 - Catch error when occures in OK method OData 防止在发生错误时关闭表单 - Prevent the Form from closing when ERROR occures 尝试启动进程时发生ThreadStateException - ThreadStateException occures when trying to start a process
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM