henkmollema / Dommel

CRUD operations with Dapper made simple.
MIT License
611 stars 99 forks source link

Problem in insert in mySQL. #181

Closed hatosbarbosa closed 4 years ago

hatosbarbosa commented 4 years ago

I'm currently using Dommel and Dapper.FluentMap.Dommel as ORM to a mySQL database. The problem I'm facing is that I have a column named status , and I get the following error while trying to insert a new row.

MySql.Data.MySqlClient.MySqlException HResult=0x80004005 Message=Field 'status' doesn't have a default value Source=MySqlConnector StackTrace: at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 130

Inner Exception 1: MySqlException: Field 'status' doesn't have a default value

I've double and triple checked the status value in my object and it's not null. I'm suspicious that the problem is that status is a reserved keyword in SQL and Dommel doesn't add the Escape characters to the SQL.

Is there a workaround for it?

hatosbarbosa commented 4 years ago

I've kept digging and found out that the problem is actually caused from a property that is private set . Although it's public get, why can't it be private settable?

TroySchmidt commented 4 years ago

I have used properties with public type Property { get; private set; } with SQL Server no issue. I haven't tested that with MySQL though. It is very usable for getting computed properties in query, but not passing it to insert and updates.

henkmollema commented 4 years ago

@hatosbarbosa which versions of the packages are you using? And what does your model look like?