たぶん、あなたは、文字列のサポートされている言語と使用ヘルパーの列挙型を作成することができます。
public enum SupportedLanguages
{
[Description("sl-SL")]
Sl,
[Description("hr-HR")]
Hr,
[Description("ru-RU")]
Ru
}
public static string GetDescription(this Enum value)
{
FieldInfo field = value.GetType().GetField(value.ToString());
DescriptionAttribute attribute
= Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute))
as DescriptionAttribute;
return attribute == null ? value.ToString() : attribute.Description;
}
その後、あなたは、移行時にそれを行う必要があり、この
[Table("User")]
public class User
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
private SupportedLanguages language;
public SupportedLanguages Language
{
get { return language; }
set
{
if(!Enum.IsDefined(typeof(SupportedLanguages), value))
throw new ArgumentOutOfRangeException();
language = value;
}
}
[NotMapped]
public CultureInfo Culture => string.IsNullOrWhiteSpace(Language.GetDescription()) ? Thread.CurrentThread.CurrentCulture : new CultureInfo(Language.GetDescription());
}
'ctx.Database.ExecuteSqlCommand("ユーザー(言語)の値(22)に挿入する "))と' user.Language =(SupportedLanguages)22'はどうでしょうか? –
それはエラーを発生させるでしょう – Emad
確かに、あなた自身でそれを試すことができます –