使用Entity Framework和MySQL安装.NET Framework 4.5后出现异常

时间:2013-01-04 13:13:13

标签: .net mysql entity-framework

我正在使用.Net Framework 4和MySQL开发应用程序。 由于ORM实体框架与6.6.4版本的MySQL Connector一起用作数据提供者。

尝试执行以下代码片段时抛出NotSupportedException。

using (var connection = new Connection())
{
    var commandTxt = 
@"SELECT
    t.ID,
    ANYELEMENT
    (
        SELECT VALUE TOP(1) c.Name
        FROM Connection.Contacts AS c
        WHERE c.PartyID = t.ID
    ) AS SubQuery
FROM Connection.Parties AS t";
    var q = new ObjectQuery<DbDataRecord>(commandTxt, connection);
    var result = q.ToList();
}

例外:

System.Data.EntityCommandCompilationException: An error occurred while preparing the command definition. See the inner exception for details. ---> System.NotSupportedException: Specified method is not supported.
   at MySql.Data.Entity.SqlGenerator.Visit(DbApplyExpression expression)
   at System.Data.Common.CommandTrees.DbApplyExpression.Accept[TResultType](DbExpressionVisitor`1 visitor)
   at MySql.Data.Entity.SqlGenerator.VisitInputExpression(DbExpression e, String name, TypeUsage type)
   at MySql.Data.Entity.SelectGenerator.VisitInputExpressionEnsureSelect(DbExpression e, String name, TypeUsage type)
   at MySql.Data.Entity.SelectGenerator.Visit(DbProjectExpression expression)
   at System.Data.Common.CommandTrees.DbProjectExpression.Accept[TResultType](DbExpressionVisitor`1 visitor)
   at MySql.Data.Entity.SelectGenerator.GenerateSQL(DbCommandTree tree)
   at MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
   at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
   at System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
   --- End of inner exception stack trace ---
   at System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
   at System.Data.EntityClient.EntityProviderServices.CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
   at System.Data.EntityClient.EntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
   at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
   at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, ReadOnlyCollection`1 compiledQueryParameters, AliasGenerator aliasGenerator)
   at System.Data.Objects.EntitySqlQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery.ToTraceString()
   at WpfApplication1.MainWindow.ExecuteQuery(String txtParam, String& query, String& result) in c:\Users\andrienko.EDSSON\Documents\Visual Studio 2012\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs:line 96

数据模型:

CREATE DATABASE `test_schema` /*!40100 DEFAULT CHARACTER SET latin1 */;

CREATE TABLE `party` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`ID`)
);

CREATE TABLE `contact` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `PartyID` int(11) NOT NULL,
  `Name` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`ID`,`PartyID`),
  KEY `fk_contact_party_idx` (`PartyID`),
  CONSTRAINT `fk_contact_party` FOREIGN KEY (`PartyID`) REFERENCES `party` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
);

此行为只能在已安装.Net Framework 4.5的计算机上重现(不对解决方案设置进行任何更改),但在仅安装了.Net Framework 4的计算机上可以正常工作。 似乎.Net Framework 4.5安装取代了System.Data.dll库。

有人可以建议任何解决方法吗?

0 个答案:

没有答案