A
A
artshelom2019-01-28 07:36:47
ASP.NET
artshelom, 2019-01-28 07:36:47

How to make a one-to-one relationship in migration?

How can one-to-one connectivity be made in migration?
I'm trying to do it with ForeignKey:

public class SettingModel
  {
    [Key]
    [ForeignKey("ApplicationUser")]
    public int Id { get; set; }

    public string Sound { get; set; }
    public ApplicationUser User { get; set; }
  }
  public class SettingModelContext : DbContext
  {
    public DbSet<SettingModel> Phones { get; set; }
    public SettingModelContext() : base("SettingModelContextConnection")
    { }
  }

But when I update the console it says:
Недопустимый атрибут ForeignKeyAttribute в свойстве "Id" в типе "ExampleCustomUserAndRole.Models.SettingModel". Имя свойства навигации "ApplicationUser" не найдено в зависимом типе "ExampleCustomUserAndRole.Models.SettingModel". Значение Name должно быть допустимым именем свойства навигации.

How is migration different from files in App_Data?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question