Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get mysql char column type from C# Entity Framework Code First Model
    primarykey
    data
    text
    <p>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:</p> <pre><code>class Preferences { [Key] public string StationName { get; set; } [MaxLength(30)] public string MainDatabase { get; set; } [MaxLength(30)] public string DefaultSequence { get; set; } } </code></pre> <p>and then had a little routine to add a record</p> <pre><code>var newPrefs = new Preferences { StationName = "MATT", DefaultSequence = "NONE", MainDatabase = "NONE" }; Preferences prefs = foo.Preferences.Add(newPrefs); </code></pre> <p>which then tries to create the database and fails when adding the primary key with the error </p> <pre><code>"BLOB/TEXT column 'StationName' used in key specification without a key length" </code></pre> <p>because it uses the data type "mediumtext" instead of CHAR or VARCHAR and MySQL can't use that type for a key. </p> <p>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?</p> <p>I also tried variations of the design like this but nothing worked.</p> <pre><code>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; } } </code></pre> <p>Thanks for your help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload