Entity Framework Foreign Key as Primary Key Code First

前端 未结 1 371
无人及你
无人及你 2021-02-07 02:11

I have two code first models, Foo and FooState where Foo has an optional FooState.

public class Foo
{
    [Key]
    public int FooId { get; set; }

    public Fo         


        
相关标签:
1条回答
  • 2021-02-07 02:45

    I thought I'd give this a shot and it worked nicely.

    public class FooState
    {
        [Required]
        [Key]
        [ForeignKey("Foo")]
        public int FooStateId { get; set; }
    
        [Required]
        public int State { get; set; }
    
        public Foo Foo { get; set; }
    }
    
    0 讨论(0)
提交回复
热议问题