在EntityFrameWork中定义值对象时应注意:

1.不要在DBContext中声明。

2.不要定义Key(主键)

3.可以在类的顶部显示声明[ComplexType]

4.其他实体引用时只能单个引用,不能引用列表

5.由于值对象要求是只读的,定义属性时应:

        private string content;//对的

        public string Content
        {
            get { return content; }
            private set { content = value; }
        }

 

而不要像以下这么定义,EF不会将其映射到数据库,也就会报错:

      private string content;//错的

        public string Content
        {
            get { return content; }
        }

 

相关文章:

  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2021-12-30
  • 2021-10-22
  • 2021-04-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-09-07
  • 2022-12-23
  • 2021-12-03
  • 2022-01-04
相关资源
相似解决方案