Отношения «один к одному» с Fluent API и Entity Framework.Как использовать свойства WithRequiredDependent и Principal - PullRequest
0 голосов
/ 26 декабря 2018

Я немного запутался в том, как использовать эти свойства.У меня есть класс InfoAppointment, который требует в качестве обязательного класса Boat и необязательно классов WeatherInformation и Positioning.Поэтому я использовал свойство WithRequiredDependent () в отображении класса InfoAppointment, чтобы сказать, что класс лодки является обязательным, но это немного сбивает с толку, потому что у моего класса InfoAppointment должна быть лодка, а не лодка, зависит от класса InfoAppointment.Как и необязательные классы, это также немного сбивает с толку.

В отличие от отношения один ко многим, я не могу сказать, каким является внешний ключ таблиц Boat, WeatherInformation и Positioning в таблице InfoAppointment.Откуда я знаю внешние ключи этих таблиц?

Я использовал документацию, чтобы получить здесь, но я не мог понять, как это работает под ним.Может ли кто-нибудь помочь мне понять и сказать, правильное ли это решение?

public  class InfoAppointment : Entity
{      
    public string Status { get; set; }

    public string Observation{ get; set; }

    public Guid BoatId{ get; set; }

    public Guid WeatherInformationId{ get; set; }


    public virtual Boat Boat { get; set; }

    public virtual WeatherInformation WeatherInformation { get; set; }

    public virtual Positioning Positioning{ get; set; }
}


 public class Boat : Entity
{
   public Guid BoatId { get; set; }
   public virtual InfoAppointment  InfoAppointment { get; set; }

} 

public class Positioning : Entity
{
    public Guid PositioningId { get; set; }
    public virtual InfoAppointment  InfoAppointment { get; set; }

} 

public class WeatherInformation : Entity
{
   public Guid WeatherId { get; set; }
   public string WindDirection{ get; set; }
   public virtual InfoAppointment  InfoAppointment { get; set; }

} 

Mappings

    public class InfoAppointment Config : EntityTypeConfiguration<InfoAppointment >
{
    public InfoAppointmentConfig()
    {
         HasRequired(c => c.Boat)
              .WithRequiredDependent(c => c.InfoAppointment )

         HasRequired(c => c.Positioning )
              .WithOptional(c => c.InfoAppointment )

         HasRequired(c => c.WeatherInformation )
              .WithOptional(c => c.InfoAppointment )

 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...