I have just done the equivalent of Hello World by creating an Entity Framework Code First model (I have written other C# programs but not with Entity Framework). I created a model like this:
class Preferences
{
[Key]
public string StationName { get; set; }
[MaxLength(30)]
public string MainDatabase { get; set; }
[MaxLength(30)]
public string DefaultSequence { get; set; }
}
and then had a little routine to add a record
var newPrefs = new Preferences
{
StationName = "MATT",
DefaultSequence = "NONE",
MainDatabase = "NONE"
};
Preferences prefs = foo.Preferences.Add(newPrefs);
which then tries to create the database and fails when adding the primary key with the error
"BLOB/TEXT column 'StationName' used in key specification without a key length"
because it uses the data type "mediumtext" instead of CHAR or VARCHAR and MySQL can't use that type for a key.
Is there a method that is still more-or-less database agnostic that will tell MySQL to use the preferred type for the key column? Or do I just have to give up and make an integer key?
I also tried variations of the design like this but nothing worked.
class Preferences
{
[Key,DataType("CHAR"),StringLength(30)]
public string StationName { get; set; }
[MaxLength(30)]
public string MainDatabase { get; set; }
[MaxLength(30)]
public string DefaultSequence { get; set; }
}
Thanks for your help.