Entity Framework Code First List Property Mapping

后端 未结 2 1081
孤独总比滥情好
孤独总比滥情好 2020-12-05 14:09

I am working with Entity Framework Code first. I have a simple model:

public class Variable
{
    public string Name { get; set; }

    public int Id { get;          


        
2条回答
  •  执念已碎
    2020-12-05 14:57

    No, EF doesn't have any type converters or custom type mappers as alternative to model binders from MVC. You must always use some hack to force persistence. Another way to do the same is mapping TextOptions as collection of related entities. It will make your separation of concerns better but it will complicate your model and working with Variable.

    public class Variable
    {
        public string Name { get; set; }
    
        public int Id { get; set; }
    
        public IList TextOptions
        {
            get;
            set;
        }
    }
    
    public class TextOption
    {
        public int Id { get; set; }
        public string Text { get; set; }
    }
    

提交回复
热议问题