0

.Net Framework 4 と MySQL を使用してアプリケーションを開発しています。ORM Entity Framework は、データ プロバイダーとして MySQL コネクタの 6.6.4 バージョンで使用されます。

次のコード スニペットを実行しようとすると、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 ライブラリが置き換えられたようです。

誰かが回避策を提案できますか?

4

0 に答える 0