Я основал аналогичный вопрос, но я застрял. ключ. Чтобы явно урегулировать это свойства внешнего ключа, по крайней мере, на одном из отношений.public class Speaker : PlanificadorDTO.Speaker
{
public virtual ICollection SessionSpeakers { get; set; } = new List();
}
public class SessionSpeaker
{
public int SessionId { get; set; }
public Session Session { get; set; }
public int SpeakerId { get; set; }
public Speaker Speaker { get; set; }
}
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions options)
: base(options)
{
}
////cuando se cree el modelo en Entity..
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity()
.HasIndex(a => a.UserName)
.IsUnique();
// Ignore the computed property
modelBuilder.Entity()
.Ignore(s => s.Duration);
// Many-to-many: Conference Attendee
modelBuilder.Entity()
.HasKey(ca => new { ca.ConferenceID, ca.AttendeeID });
// Many-to-many: Session Attendee
modelBuilder.Entity()
.HasKey(ca => new { ca.SessionID, ca.AttendeeID });
// Many-to-many: Speaker Session
modelBuilder.Entity()
.HasKey(ss => new { ss.SessionId, ss.SpeakerId });
// Many-to-many: Session Tag
modelBuilder.Entity()
.HasKey(st => new { st.SessionID, st.TagID });
}
public DbSet Conferences { get; set; }
public DbSet Sessions { get; set; }
public DbSet Tracks { get; set; }
public DbSet Tags { get; set; }
public DbSet Speakers { get; set; }
public DbSet Attendees { get; set; }
}
< /code>
dto: < /p>
динамик: < /p>
public class Speaker
{
public int ID { get; set; }
[Required]
[StringLength(200)]
public string Name { get; set; }
[StringLength(4000)]
public string Bio { get; set; }
[StringLength(1000)]
public virtual string WebSite { get; set; }
public DateTime Nacimiento { get; set; }
}
< /code>
session: < /p>
public class Session
{
public int ID { get; set; }
[Required]
public int ConferenceID { get; set; }
[Required]
[StringLength(200)]
public string Title { get; set; }
[StringLength(4000)]
public virtual string Abstract { get; set; }
public virtual DateTimeOffset? StartTime { get; set; }
public virtual DateTimeOffset? EndTime { get; set; }
public TimeSpan Duration => EndTime?.Subtract(StartTime ?? EndTime ?? DateTimeOffset.MinValue) ?? TimeSpan.Zero;
public int? TrackId { get; set; }
}
< /code>
Оба отношения между «sessionspeaker.speaker» и «speaker» и между 'sessionspeaker' и 'speaker.sessionspeakers' могут использовать {'speakerid'} в качестве иностранного ключа. Чтобы решить эту настройку свойств иностранного ключа явно по крайней мере на одном из отношений. < /P>
Спасибо за помощь < /p>
Подробнее здесь: https://stackoverflow.com/questions/587 ... -least-one