Reputation: 1122
I have an application that is using EntityFramework Code First to create the database if it doesnt exist. And Im using MySQL for the database engine.
I have a table where one of the Key columns needs to be Case-Sensitive. I dont want to mark the entire database or table as case-sensitive using collation, so the best way to do it (that I know of) is to mark the column as BINARY.
Does anyone know how to do this using Code First? I tried doing:
[Column(TypeName = "varchar(100) BINARY")]
but it doesn't like that, the first time I access the DB Model I get
An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code
Additional information: Sequence contains no matching element
Maybe I should just do an ALTER TABLE after the database is created?
Upvotes: 1
Views: 840
Reputation: 179404
I dont want to mark the entire database or table as case-sensitive using collation
Well, no, that doesn't make sense, but you should be able to do it on the column, using an appropriate collation, e.g.:
VARCHAR(100) COLLATE utf8_bin
Or just...
VARBINARY(100)
...is perfectly valid in MySQL (though I have no idea about whether EF will handle it correctly).
http://dev.mysql.com/doc/refman/5.7/en/binary-varbinary.html
Upvotes: 1