MySql + entity framework =每个派生表都必须有自己的别名 [英] MySql + entity framework = Every derived table must have its own alias

查看:400
本文介绍了MySql + entity framework =每个派生表都必须有自己的别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从我的C#程序访问另一个开发人员的一些MySql视图。



所以经过一些搜索,我决定了实体框架,并使用这个问题提到的驱动:使用MySQL与实体框架 MySQL .NET连接器)。



现在,我试图获得一个视图的第一个元素:

  myEntities.events.First(); 

那里有一个例外:



< pre class =lang-none prettyprint-override> System.Data.EntityCommandExecutionException未处理
消息=执行命令定义时发生错误。查看内部例外情况。
Source = System.Data.Entity
StackTrace:
在System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior行为)
在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.Linq.Enumerable.First [TSource](IEnumerable`1源)
在System.Data.Objects.ELinq.ObjectQueryProvider 。< GetElementFunction> b__0 [TResult](IEnumerable`1序列)
在System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle [TResult](IEnumerable`1查询,表达式queryRoot)
在系统。 Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute [S](表达式表达式)
在System.Linq.Queryable.First [TSource](IQueryable`1源)
在J4N.GroopleReports.ReportManager.DataImporter.GenerateEvent(GroopleEntities groovepleEntities)在C:\Users\J4N\Dropbox\工作空间\DotNET\GroopleReports\ReportManager\DataImporter.cs:line 35
在J4N.GroopleReports.ReportManager.DataImporter.Import()在C:\Users\J4N\Dropbox\WorkSpaces\\ \\ DotNET\GroopleReports\ReportManager\DataImporter.cs:line 17
在ImportTest.Program.Main(String [] args)在C:\Users\J4N\Dropbox\WorkSpaces\DotNET System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,String [] args))中的$ \\ $ G $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ String [] args)
在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在Sys system.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean ignoreSyncCtx)
在System.Threading.ExecutionContext.Run(ExecutionContext executeContext,ContextCallback callback,Object state)
在System.Threading.ThreadHelper.ThreadStart()
InnerException:MySql.Data.MySqlClient.MySqlException
Message =每个派生表必须有自己的别名
Source = MySql.Data
ErrorCode = -2147467259
Number = 1248
StackTrace:
在MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(的Int32&安培; affectedRow,Int32& insertId)
在MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId,Int32& affectedRows,Int32& insertedId)
在MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId,Boolean force)$在MySql.Data.MySqlClient.MySqlDataReader.NextResult()中的
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior行为)中的
$ MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior行为)中的

在System.Data.Common.DbCommand.ExecuteReader(CommandBehavior行为)
在System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior行为)
InnerException:

我搜索了什么是这个错误每个派生表必须有自己的别名以及如何解决它,我发现一些对网络上的响应有关SQL请求有什么问题,但是我不能影响如何enti

解决方案

除了接受的答案外,还应该注意到同样的例外(如果您尝试将数据库中的更改保存在没有主键的表上,则派生表必须具有自己的别名)。



这是一个已知错误,多年后仍然未解决(出现在MySQL 5.5中) 22 + .Net / Connector 6.5.4 on 04/04/12)。



我知道拥有没有主键的表不是一个好主意,但是像那样是DDL生成器中的另一个错误,一些表中关联的实体键具有属性 StoreGeneratedPattern 设置为无创建没有主键...


I've got to access to some MySql views of another developer from my C# program.

So after some search I decided entity framework, and to use the driver mentioned in this question: Using MySQL with Entity Framework (MySQL .NET Connector).

Now, I'm trying to get the first element of one view:

myEntities.events.First();

and there, I get an exception:

System.Data.EntityCommandExecutionException was unhandled
  Message=An error occurred while executing the command definition. See the inner exception for details.
  Source=System.Data.Entity
  StackTrace:
       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.Linq.Enumerable.First[TSource](IEnumerable`1 source)
       at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__0[TResult](IEnumerable`1 sequence)
       at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
       at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
       at System.Linq.Queryable.First[TSource](IQueryable`1 source)
       at J4N.GroopleReports.ReportManager.DataImporter.GenerateEvent(GroopleEntities groopleEntities) in C:\Users\J4N\Dropbox\WorkSpaces\DotNET\GroopleReports\ReportManager\DataImporter.cs:line 35
       at J4N.GroopleReports.ReportManager.DataImporter.Import() in C:\Users\J4N\Dropbox\WorkSpaces\DotNET\GroopleReports\ReportManager\DataImporter.cs:line 17
       at ImportTest.Program.Main(String[] args) in C:\Users\J4N\Dropbox\WorkSpaces\DotNET\GroopleReports\ImportTest\Program.cs:line 15
       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.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: MySql.Data.MySqlClient.MySqlException
       Message=Every derived table must have its own alias
       Source=MySql.Data
       ErrorCode=-2147467259
       Number=1248
       StackTrace:
            at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
            at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId)
            at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& insertedId)
            at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
            at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
            at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
            at MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
            at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
            at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
       InnerException: 

I searched what is this error "Every derived table must have its own alias" and how to resolve it, I found some responses on the net about what is wrong on a SQL request, but I cannot influence how entity framework constructs those.

解决方案

In addition to the accepted answer, it should be noted that the same exception (Every derived table must have its own alias) will be thrown if you try to save changes in the database on a table that has no primary key.

This is a known bug that is still not fixed after years (appeared in MySQL 5.5.22 + .Net/Connector 6.5.4 on 04/04/12).

I know it's not a good idea to have a table without primary key, but as there is another bug in the DDL generator, some tables where the associated entity key has the property StoreGeneratedPattern set to None are created without primary key...

这篇关于MySql + entity framework =每个派生表都必须有自己的别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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