Recently I discovered the beauty of Entity Framework 6 and decided to implement it in my current project. However, I stumbled upon a weird problem today. I have been searching the internet for hours, but I did not come to any solution yet.
First, some info which might be of use;
The problem: For some reason, EF is generating a query containing "\n". Since my error goes as follows;
"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(SELECT\n
table.column1, \ntable.column2, \ntable.column3at line 1"
I literally copied the query in my database interface (which is HeidiSql, for those who are interested) and after I remove the "\n", the query seems to work fine.
The error is thrown at:
using(var db = new DataContext())
{
table tab = new table
{
column1 = "Some value",
column2 = "Some other value",
column3 = "Yet, another value"
};
db.table.Add(tab);
db.SaveChanges(); //This is where the error occurs
}
I have debugged the input and it is correct. Also, the table is correctly added to the table entity. The code also compiles like it should.
Strange thing is, this is the only place where the error occurs (yet - I have to test it more to be sure of that). I call db.SaveChanges() in other places and somehow it does not throw any error there. In other words; I am actually able to add and save data to the database for other, more complex tables. This one, somehow, does not seem to work.
The table does not contain any primary or foreign keys (it really doesn't need any either, I've thought about it.).
Am I missing something here?
In EF you can't have a mapped entity without defining a PK.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With