jonpryor / dblinq2007

Automatically exported from code.google.com/p/dblinq2007
0 stars 0 forks source link

DbMetal: Linq to Mysql and Constraints problem Error: The given key was not present in the dictionary #315

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Build a schema with tables at mysql with all constraints of relationships 
between tables.
2.Run DbMetal to generate .cs and .dbml
3.You will get a error.

What is the expected output? What do you see instead?
The expected output is the .cs and .dbml of schema with all tables, columns and 
constraints.

But... the system give me the message "DbMetal: The given key was not present 
in the dictionary".

I Discovery the error is in MySql when dbMetal run the method ReadConstraints 
with parameters (IDbConnection conn, string db) it run the query:

SELECT constraint_name,table_schema,table_name
,GROUP_CONCAT(column_name SEPARATOR ',') AS column_name,
referenced_table_schema,
referenced_table_name,
GROUP_CONCAT(referenced_column_name SEPARATOR ',') AS referenced_column_name
FROM 
information_schema.`KEY_COLUMN_USAGE`
WHERE table_schema=?db
GROUP BY constraint_name,table_schema,table_name,referenced_table_name;

but i think there is a bug in mysql what return the referenced_column_name with 
uppercase chars, then the keys not match with the name and returns the error.

My Solution was change the query to lower the referenced_column_name:
.
.
.
lower(GROUP_CONCAT(referenced_column_name SEPARATOR ',')) AS 
referenced_column_name
.
.
.

This solve my problem. I wait help somebody.
Sorry the english. =P

Original issue reported on code.google.com by fernando...@gmail.com on 28 May 2011 at 1:43