I'm using Entity Framework 5, MySQL 5.6 and MySQLConnector 6.6.5.
I would like to set up the FOUND_ROWS flag in my Entity Framework connection string.
I tried the following configuration.
...
server=localhost;user id=root;option=2
..
According to the MySQL documentation the value '2' equals FOUND_ROWS parameter.
But it throws an InvalidOperationException saying that the Keyword is not supported (name parameter : option).
How am I supposed to do?
try
UseAffectedRows=false
reference.
UseAffectedRows
When true, the connection reports changed rows instead of found rows.
This option was added in Connector/Net version 5.2.6.
Related
The following SQL runs as expected in the workbench, but generates an error "parameter #search must be defined" when I fire it in from a C# application. Can anyone explain this?
set #search = 'b%';
select * from country where Name like #search
MySQL use the #variable_name expression as a user defined variable. C# (or the provider - not really sure which) on the other hand uses the #parameter_name to annotate parameter placeholder in the query.
If you want to use sql user defined variables, then add the following parameter to the connection string of your .Net connector connection:
Allow User Variables=True
or
AllowUserVariables=True
This option was added to connector v5.2.2
I am trying to do a very simple sql select statement from a MySQL database:
Dim lDatabase As Database = DatabaseFactory.CreateDatabase("FTP")
lSqlString = String.Format(CultureInfo.CurrentCulture, "SELECT monthends.web_usr FROM monthends")
lDBCommand = lDatabase.GetSqlStringCommand(lSqlString)
lUsers = lDatabase.ExecuteDataSet(lDBCommand)
And on the execute dataset line I receive the following ODBC Exception:
In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.
I don't get it. This is the simplest of simple sql statements and it has all worked just fine in the past, why doesn't this work anymore???
Thanks in advance!
What was going on was that there was an incorrect version of the MySQL ODBC 3.5xx driver installed. I contacted the DB Admin and got the correct version, it all works now as it should.
I'm using Entity Framework with MySQL, and my Linq Query:
db.Persons.Where(x => x.Surname.StartsWith("Zyw")).ToList();
..is producing the SQL:
SELECT PersonId, Forename, Surname
FROM Person
WHERE (LOCATE('Zyw', Surname)) = 1
...and it would seem that this doesn't make use of the index on Surname.
If LOCATE is replaced with the equivalent LIKE, the query speedily returns the required results. As it is it takes all afternoon.
Why is Entity Framework and its connecting drivers opting for this wierd LOCATE function / how can I make it use LIKE instead / why is MySQL making a poor index decision for the LOCATE function / how can I make it better?
Update:
I'm afraid I was guilty of over simplifying my code for this post, the Linq producing the error is in fact:
var target = "Zyw";
db.Persons.Where(x => x.Surname.StartsWith(target)).ToList();
If target term is hard coded, the SQL generated does indeed use LIKE, but with a variable term the SQL changes to use LOCATE.
This is all using the latest generally available MySQL for Windows as delivered by MySQL Installer 5.6.15.
Update:
A couple more notes to go with the bounty; am using:
Visual Studio 2010
EntityFramework 6.0.2
MySQL Installer 5.6.15,
which in turn gives:
MySql.Data 6.7.4
MySql.Data.Entities 6.7.4
The Entity Framework code is generated database first style.
I've also tried it with the latest connector from Nuget (MySql.Data 6.8.3) and the problem is still there.
It's likely your problem is caused by:
You are using an older connector with the bug.
You have a special case (using a variable to hold the .Contains search) described as a bug here
Does your case fall into any of those?
This looks like a regression of MySQL bug #64935 to me.
I can confirm that, using the same builds of EF6 and MySQL Connector, I'm getting the same SQL generated too:
context.stoppoints.Where(sp => sp.derivedName.StartsWith(stopName));
...logs as:
SELECT
`Extent1`.`primaryCode`,
...
`Extent1`.`stop_timezone`
FROM `stoppoints` AS `Extent1`
WHERE (LOCATE(#p__linq__0, `Extent1`.`derivedName`)) = 1
Entity Framework: 6.0.2
MySQL Connector.Net: 6.8.3
I have reported this as a MySQL bug regression.
I have an issue with Entity Framework 5.0. I'm working with Silverlight 5 and MySQL 5.6 too.
I need to set an environment MySQL variable before each connexion to the MySQL server.
E.g
SET #my_var = 'test';
Under Mysql I don't have any issues.
The following raises an EntityFrameworkException (syntax error near '#').
this.ObjectContext.CreateQuery<object>(" SET #my_var = 'test' ");
OR
this.ObjectContext.CreateQuery<object>(" CALL set_my_var('test') ");
This last method raises a MySQLException saying that a DataReader is already open and need to be closed.
this.ObjectContext.ExecuteStoreQuery<object>(" CALL set_my_var('test') ", null);
I also tried to set a MySQL system environment (no '#') with the same result every time.
Any help will be much appreciated !
Thank you.
I tried so many things that I misspelled my variable in my code.
So the following finaly worked : ctx.ExecuteStoreCommand("SET #my_var = 'test'");
I decided to leave the instruction in the method Initialize of my domain service. This method is inherited of the LinqToEntitiesDomainService class.
But you need to set Allow User Variables=True in your MySQL connection string
(ref : Is it possible to use a MySql User Defined Variable in a .NET MySqlCommand?)
You simply need to use a recent version of the MySQL Connector because older versions use the '#' mark to define SQL parameters so it could conflict with custom variables. Now it uses the '?' mark : http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqlcommand.html
My library was already up to date (6.6.5).
Thank you for the help !
Since your statement is not a query (i.e. does not return any result) you should use ExecuteStoreCommand. Something like this should work:
ctx.ExecuteStoreCommand("SET #my_var = 'test'")
Searching, reading forums and all suggestion of SO before writing. (1 day already investigating the issue).
Im using: MySql Server 5.5 with Entity Framework 4.3 with Connector 6.5.4
(I was using connector 6.3.6 and everything worked perfectly, updated and problem occurs)
I have a SP that returns an List of an Entity Object. That Entity have a bool (tinyint(1)) field BUT when using the SP it returns it as string.
I created a temporary table and return that but the same problems occurs. The error is:
System.InvalidOperationException: The 'isDeleted' property on 'Container' could not be
set to a 'String' value. You must set this property to a non-null value of type
'Boolean'. at
System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.
GetValue(DbDataReader reader, Int32 ordinal)
Problem is, since it's a Entity object, i cannot Convert.ToBoolean() [also i dont want to].
I think the problem is that i don't have the ability to cast the SP field as bool or the connector has a bug (most likely).
As I said, it worked with no problem with connector 6.3.6
Thanks.
The bug is there but I found a workaround. The problem happend when the order of the fields aren't the same.
This BUG: http://bugs.mysql.com/bug.php?id=53166 helped me to understand and try making the select order of fileds the same the table.
Example:
If table is :
field_a, field_b, field_c
and your stored procedures returns: field_b, field_a, field_c won't work.
Changed my SP to return field_a, field_b, field_c