从EF4代码获取SqlException“无效的列名'User_Id' [英] Getting SqlException "Invalid column name 'User_Id' from EF4 code-only

查看:55
本文介绍了从EF4代码获取SqlException“无效的列名'User_Id'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个奇怪的行为只有代码(EF CTP),我得到一个EntityCommandExecutionException,内部异常是一个SQLException说:无效的列名'User_Id'。

这个奇怪的事情是我的POCO不包含User_Id(在我的整个解决方案中甚至没有这样的字段/属性)。

这是来自EntityCommandExecutionException的堆栈跟踪:

在System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior behavior)
在System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute [TResultType](ObjectContext context,ObjectParameterCollection parameterValues)
在System.Data .Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
在System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable< T> .GetEnumerator()
在System。 System.Linq.Enume上的Collections.Generic.List`1..ctor(IEnumerable`1集合)

rable.ToList [TSource](IEnumerable`1 source)
在C:\Projects \ Storages.EF\EFRepository.vb中的Repositories.EF.EFRepository`2.GetAll():第64行 at epositories.Website.EFBlogAggregateRepository.GetAllBlogs()位于C:\Projects \ Storages.Website\EntityFramework \Repositories \AggregateRepositories \EFBlogAggregateRepository.vb:第18行,位于Repositories.Test.BlogTest。 GetAllBlogs()在C:\Projects\Repositories.Test \ BlogTest.vb:第70行年

是否有人知道这里发生了什么?

I got a strange behaviour with code only (EF CTP) where I get an EntityCommandExecutionException, and the inner exception is a SQLException saying: Invalid column name 'User_Id'.

The strange thing with this is that my POCO does not contain a User_Id (there is even no such field/property in my whole solution).

Here is the stack trace from the EntityCommandExecutionException:

   at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Repositories.EF.EFRepository`2.GetAll() in C:\Projects\Repositories.EF\EFRepository.vb:line 64
   at epositories.Website.EFBlogAggregateRepository.GetAllBlogs() in C:\Projects\Repositories.Website\EntityFramework\Repositories\AggregateRepositories\EFBlogAggregateRepository.vb:line 18
   at Repositories.Test.BlogTest.GetAllBlogs() in C:\Projects\Repositories.Test\BlogTest.vb:line 70

Does anybody have an idea what is going on here?

推荐答案

奇怪的是,SQL Profiler显示EF实际上试图检索列"User_Id"。来自数据库...

选择
1 AS [C1],[[范围1]。[Id] AS [Id],[Extent1]。[名称] AS [名称],
[Extent1]。[User_Id] AS [User_Id]
FROM [dbo]。[博客] AS [Extent1]
Strange enough, an SQL Profiler shows that EF actually tries to retrieve a column "User_Id" from the database...

SELECT
1 AS [C1],
[Extent1].[Id] AS [Id],
[Extent1].[Name] AS [Name],
[Extent1].[User_Id] AS [User_Id]
FROM [dbo].[Blogs] AS [Extent1]


这篇关于从EF4代码获取SqlException“无效的列名'User_Id'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆