Fluent Api Entity Framework core

后端 未结 2 1162
终归单人心
终归单人心 2021-01-12 15:01

A user can have 1 or 0 account

public class User
    {
        public int UserId { get; set; }
        public string Name { get; set; }
        public string         


        
2条回答
  •  萌比男神i
    2021-01-12 15:41

    Pretty much the same, with other names.

    modelBuilder.Entity()
        .HasOne(s => s.Account) 
        .WithOne(ad => ad.User)
        .IsRequired(false);
    

提交回复
热议问题