C
C#10mo ago
Mariannnn

❔ EF Core Adding "1" to Column Name

Hello, I got a problem while configuring a one-to-many relationship in .NET EF Core. This is the parent class Coaches: public class Coaches { public Guid CoachId { get; set; } public virtual ICollection<License> License { get; set; } public Coaches() { License = new HashSet<License>(); } } This is the second class License: public class License { public Guid LicenseId { get; set; } public Guid CoachId { get; set; } public virtual Coaches Coach { get; set; } } Coaches entity builder configuration:
modelBuilder.Entity<Coaches>(entity => { entity.HasKey(e => e.CoachId); entity.Property(e => e.CoachId).ValueGeneratedNever(); entity.HasOne(p => p.Person) .WithOne(p => p.Coach) .HasForeignKey<Coaches>(p => p.PersonId) .OnDelete(DeleteBehavior.Restrict) .HasConstraintName("FK_Coaches_Person"); }); License entity builder configuration: modelBuilder.Entity<License>(entity => { entity.HasOne(d => d.Coach) .WithMany(p => p.License) .HasForeignKey(d => d.CoachId) .OnDelete(DeleteBehavior.Restrict) .HasConstraintName("FK_License_Coaches");
}); When I run this query: var license = await _context.License .Where(c => c.LicenseId == command.LicenseId)
.FirstOrDefaultAsync(); -> I get the error: Invalid column name 'CoachId1'
1 Reply
Accord
Accord10mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.