0

I'm developing application using .Net Framework 4 and MySQL. As ORM Entity Framework is used with 6.6.4 version of MySQL Connector as data provider.

When trying to execute following code snippet NotSupportedException is thrown.

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();
}

Exception:

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

Data Model:

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

This behavior can be reproduces only on machine with installed .Net Framework 4.5 (without any changes to solution settings), but works fine on machine where only .Net Framework 4 installed. It seems that .Net Framework 4.5 installation replaced System.Data.dll library.

Can someone suggest any workaround?

3
  • Two points: .NET 4.5 is in place upgrade of .NET 4.0 so it indeed replaced System.Data.dll on your machine. MySql Connector 6.6.4 does not mention support of .NET 4.5. It may or may not work correctly. Jan 4, 2013 at 14:48
  • I'd recommend filing a bug on this.
    – bricelam
    Jan 4, 2013 at 23:14
  • I wonder if this is a Cross/Outer Apply issue: msdn.microsoft.com/en-us/library/bb896273.aspx given DbApplyExpression on this line at MySql.Data.Entity.SqlGenerator.Visit(DbApplyExpression expression).
    – Pawel
    Jan 5, 2013 at 1:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.