How do I remove underscore of foreign key fields in code first by convention

前端 未结 7 954
傲寒
傲寒 2020-11-30 01:20

I\'ve got multiple classes (including TPT) in my project. Each POCO has a BaseClass, which has a GUID (called GlobalKey) as primary ke

7条回答
  •  情书的邮戳
    2020-11-30 01:40

    You can do one of two things:

    1. Follow EF conventions in naming of foreign keys, i.e. if you have virtual Address, define your key property as AddressId

    2. Tell EF explicitly what to use. One way to do this is with Fluent API, as you are currently doing. You can also use data annotations, though:

      [ForeignKey("Address")]
      public int? AddressGlobalKey { get; set; }
      
      public virtual Address Address { get; set; }
      

    That's your only choices.

提交回复
热议问题