简体   繁体   English

虚拟列表 <T> :“功能评估需要所有线程运行”

[英]virtual List<T> :“The function evaluation requires all threads to run”

I am following the following tutorial to learn code fast. 我正在按照以下教程快速学习代码。 Code First to a New Database 代码优先到新数据库

I have done till the step 4: of the tutorial, the problem arises when i try to run my code. 我已经完成了本教程的第4步:当我尝试运行我的代码时出现问题。 I encounter the following exceptions at the following code... 我在以下代码中遇到以下异常...

    foreach (var item in query)
    {
        Console.WriteLine(item.Name);
    }
    {"Exception has been thrown by the target of an invocation."}

with an inner exception 有一个内在的例外

    {"Access is denied: 'CodeFastNewDatabase.Program+Blog'.":""}

when i try to check the db variable property a lot of them has the debug error saying “The function evaluation requires all threads to run” The code is creating database in my local db also inserting the values. 当我尝试检查db变量属性时,很多人都有调试错误说“函数求值需要所有线程运行”代码在我的本地db中创建数据库并插入值。

This problem I can work around if I remove the virtual specifiers in class Blog and Post for the properties 如果我删除类Blog和Post中的虚拟说明符,我可以解决这个问题

    public virtual List<Post> Posts { get; set; }
    public virtual Blog Blog { get; set; }

I am facing the same exception for my other projects as well. 我的其他项目也面临同样的例外。 A lot of properties are showing “The function evaluation requires all threads to run” 许多属性显示“功能评估需要所有线程运行”

I am working with Entity Framework 6.0 我正在使用Entity Framework 6.0

Edit: 编辑:

Blog is a property of the DbContext Object, I have initialized in the main function of the program class. Blog是DbContext对象的属性,我已经在程序类的main函数中初始化了。 Then added the blog in the context followed by saving it. 然后在上下文中添加博客,然后保存它。 That created/updated the database and inserted my given value. 创建/更新了数据库并插入了我的给定值。 the code is same as in the example link. 代码与示例链接中的代码相同。

[Stack trace] Here is the stack trace i captured. [堆栈跟踪]这是我捕获的堆栈跟踪。

   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Environment.get_StackTrace()
   at CodeFastNewDatabase.Program.Main(String[] args) in f:\Dropbox\Projects\visual studio 2012\Projects\CodeFastNewDatabase\CodeFastNewDatabase\Program.cs:line 32
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Here is the stack trace for both the exceptions (outer and inner) 这是异常(外部和内部)的堆栈跟踪

    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
    at System.Data.Entity.Core.Common.Internal.Materialization.Translator.TranslateColumnMap(Translator translator, Type elementType, ColumnMap columnMap, MetadataWorkspace workspace, SpanIndex spanIndex, MergeOption mergeOption, Boolean streaming, Boolean valueLayer)
    at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Boolean streaming, Span span, IEnumerable`1 compiledQueryParameters, AliasGenerator aliasGenerator)
    at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
    at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassb.<GetResults>b__a()
    at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
    at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassb.<GetResults>b__9()
    at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
    at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
    at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
    at System.Lazy`1.CreateValue()
    at System.Lazy`1.LazyInitValue()
    at System.Lazy`1.get_Value()
    at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
    at CodeFastNewDatabase.Program.Main(String[] args) in f:\Dropbox\Projects\visual studio 2012\Projects\CodeFastNewDatabase\CodeFastNewDatabase\Program.cs:line 33
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()

Inner Exception StackTrace 内部异常StackTrace

    at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
    at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
    at System.Reflection.Emit.TypeBuilder.CreateType()
    at System.Data.Entity.Core.Objects.Internal.EntityProxyFactory.ProxyTypeBuilder.CreateType(ModuleBuilder moduleBuilder)
    at System.Data.Entity.Core.Objects.Internal.EntityProxyFactory.BuildType(ModuleBuilder moduleBuilder, ClrEntityType ospaceEntityType, MetadataWorkspace workspace)
    at System.Data.Entity.Core.Objects.Internal.EntityProxyFactory.TryCreateProxyType(EntityType ospaceEntityType, MetadataWorkspace workspace)
    at System.Data.Entity.Core.Objects.Internal.EntityProxyFactory.GetProxyType(ClrEntityType ospaceEntityType, MetadataWorkspace workspace)
    at System.Data.Entity.Core.Common.Internal.Materialization.Translator.TranslatorVisitor.Visit(EntityColumnMap columnMap, TranslatorArg arg)
    at System.Data.Entity.Core.Query.InternalTrees.EntityColumnMap.Accept[TResultType,TArgType](ColumnMapVisitorWithResults`2 visitor, TArgType arg)
    at System.Data.Entity.Core.Common.Internal.Materialization.Translator.TranslatorVisitor.ProcessCollectionColumnMap(CollectionColumnMap columnMap, TranslatorArg arg, ColumnMap discriminatorColumnMap, Object discriminatorValue)
    at System.Data.Entity.Core.Common.Internal.Materialization.Translator.TranslatorVisitor.ProcessCollectionColumnMap(CollectionColumnMap columnMap, TranslatorArg arg)
    at System.Data.Entity.Core.Common.Internal.Materialization.Translator.TranslatorVisitor.Visit(SimpleCollectionColumnMap columnMap, TranslatorArg arg)
    at System.Data.Entity.Core.Query.InternalTrees.SimpleCollectionColumnMap.Accept[TResultType,TArgType](ColumnMapVisitorWithResults`2 visitor, TArgType arg)
    at System.Data.Entity.Core.Common.Internal.Materialization.Translator.TranslateColumnMap[T](ColumnMap columnMap, MetadataWorkspace workspace, SpanIndex spanIndex, MergeOption mergeOption, Boolean streaming, Boolean valueLayer)

The exception message shows that you've used Blog and Post as classes nested within Program , whereas the instructions state: 异常消息显示您已将BlogPost用作嵌套在Program类,而说明指出:

Below the Program class definition in Program.cs add the following two classes. 在Program.cs中的Program类定义下面添加以下两个类。

Personally I'd put them into separate files, but that's a different matter. 我个人将它们分成不同的文件,但这是另一回事。 Given that they're public classes, I'm still surprised that it's failing, but it sounds like that's the problem. 鉴于他们是公共课程,我仍然对它失败感到惊讶,但听起来这就是问题所在。

As for "The function evaluation requires all threads to run" - that's not actually an error , it's just showing a limitation of debugging when evaluating a property would need to use various threads. 至于“函数评估需要所有线程运行” - 这实际上并不是一个错误 ,它只是在评估属性需要使用各种线程时显示调试的限制。

The code you linked to is written to target Entity Framework 5. In Entity Framework 6, the virtual proxy objects use an implementation of Lazy<T> for lazy loading, and it has to be handled differently in order to be thread safe. 您链接到的代码将写入目标实体框架5.在实体框架6中,虚拟代理对象使用Lazy<T>实现进行延迟加载,并且必须以不同方式处理它才能保证线程安全。 my recommendation is to use a virtual ICollection<Post> rather than virtual List<Post> with EF6, or drop backwards to EF5, which the tutorial you are referencing is designed against. 我的建议是使用virtual ICollection<Post>而不是使用EF6的virtual List<Post> ,或者向后退到EF5,您正在引用的教程是针对EF5设计的。

我的问题是,在我的Repository中,我返回了一个IQueryable<T>但忘记了我的Service方法,对返回的结果使用ToList()方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 懒 <T> :“功能评估需要所有线程运行” - Lazy<T>: “The function evaluation requires all threads to run” 功能评估需要运行所有线程 - The function evaluation requires all threads to run 什么是 function 评估需要所有线程运行? - What is the function evaluation requires all threads to run? 调试期间的 Visual Studio:function 评估需要所有线程运行 - Visual Studio during Debugging: The function evaluation requires all threads to run VS2015 Watch LINQ var错误:函数评估需要运行所有线程 - VS2015 Watch LINQ var Error: The function evaluation requires all threads to run 如何在没有“函数求值要求所有线程都运行”的情况下在后台调用方法 - How can I call a method in the background without “The function evaluation requires all threads to run” EntityFramework中的SaveChanges()不保存更改。 显示“函数评估要求所有线程都运行” - SaveChanges() in EntityFramework not saving changes. Showing “The function evaluation requires all threads to run” ASP.NET MVC或更多VS调试问题-EF / Sql函数评估要求所有线程都运行[保持] - ASP.NET MVC or more of a VS debugging issue - EF/ Sql The function evaluation requires all threads to run [on hold] 使用 Cosmos ExecuteQuery 查询 azure 表存储时,为什么会出现“function 评估需要所有线程运行”? - Why do i get "The function evaluation requires all threads to run" when querying an azure table storage with Cosmos ExecuteQuery? VS自定义可视化工具中的“ new AdhocWorkspace()”之后,“此函数需要所有线程进行评估” - “This function requires all threads to evaluate” after `new AdhocWorkspace()` within VS custom visualizer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM