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

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

问题描述

我有访问从我的C#程序的一些MySQL的看法另一家开发商。

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

于是经过一番搜索,我决定实体框架,并利用在这个问题中提到的驱动程序:使用MySQL与实体框架的MySQL .NET连接器)。

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: 

我搜遍这是什么错误每一个派生的表必须有自己的别名,以及如何解决它,我发现在网络上关于什么是错上的SQL请求一些回应,但我不能影响如何实体框架的构建者

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.

这是一个经过多年的已知的bug 这仍然是不固定的(出现在MySQL的5.5.22 +净/连接器6.5.4在04/04/12)。

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).

我知道这不是一个好主意,有没有主键的表,但没有在DDL生成另一个bug,一些表,其中关联实体键的属性 StoreGeneratedPattern 设置为无主键创建...

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 +实体框架=每派生表必须有自己的别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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