I have a Client table with 5 foreign keys: OwnerLocation, OwnerBillTo, EnteredByProvider, sId, gId, bId
SqlServer finds a problem as per the title for bId, and I assume will do the same for sId and gId, once bId issue is taken care off.
All these relatioships are 1 Client has 1 of type foreign key
The EF Core was scaffolded from a db.
Client:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
#nullable disable
namespace BtApiCore.Model
{
public partial class Client
{
public Client()
{
Appointments = new HashSet<Appointment>();
ClientOwners = new HashSet<ClientOwner>();
ClientRecords = new HashSet<ClientRecord>();
ClientShoes = new HashSet<ClientShoe>();
CpPictures = new HashSet<CpPicture>();
TagTiles = new HashSet<TagTile>();
ToDoClientRs = new HashSet<ToDoClientR>();
TodoRecords = new HashSet<TodoRecord>();
Transactions = new HashSet<Transaction>();
}
[Key] public int ClientId { get; set; }
public string Cname { get; set; }
public string Cdescription { get; set; }
public int? OwnerLocationId { get; set; }
public bool? BillEmail { get; set; }
public string ImageName { get; set; }
public int? PropertyId { get; set; }
public bool? BillMonthly { get; set; }
public int? EnteredByProviderId { get; set; }
public bool? IsLinked { get; set; }
public int? OwnerBillToId { get; set; }
public bool? BillLocation { get; set; }
public int? SId { get; set; }
public int? GId { get; set; }
public DateTime? DofB { get; set; }
public int? BId { get; set; }
public string Rfid { get; set; }
public byte[] ImgProfile { get; set; }
[ForeignKey("BId")]
public virtual Breed BIdNavigation { get; set; }
public virtual Provider EnteredByProvider { get; set; }
[ForeignKey("GId")]
public virtual EqGender GIdNavigation { get; set; }
[ForeignKey("OwnerBillToId")]
public virtual Owner OwnerBillTo { get; set; }
[ForeignKey("OwnerLocationId")]
public virtual Owner OwnerLocation { get; set; }
[ForeignKey("SId")]
public virtual EqSize SIdNavigation { get; set; }
public virtual ICollection<Appointment> Appointments { get; set; }
public virtual ICollection<ClientOwner> ClientOwners { get; set; }
public virtual ICollection<ClientRecord> ClientRecords { get; set; }
public virtual ICollection<ClientShoe> ClientShoes { get; set; }
public virtual ICollection<CpPicture> CpPictures { get; set; }
public virtual ICollection<TagTile> TagTiles { get; set; }
public virtual ICollection<ToDoClientR> ToDoClientRs { get; set; }
public virtual ICollection<TodoRecord> TodoRecords { get; set; }
public virtual ICollection<Transaction> Transactions { get; set; }
}
}And the modelbuilder context:
modelBuilder.Entity<Client>(entity =>
{
entity.HasKey(e => e.ClientId)
.HasName("PK_Clients_ClientId");
entity.HasIndex(e => e.OwnerLocationId, "fk_stabklesInBarn");
entity.Property(e => e.BId).HasColumnName("bId");
entity.Property(e => e.BillLocation).HasColumnName("billLocation");
entity.Property(e => e.Cdescription)
.HasMaxLength(50)
.HasColumnName("CDescription");
entity.Property(e => e.Cname)
.HasMaxLength(50)
.HasColumnName("CName");
entity.Property(e => e.DofB).HasColumnType("date");
entity.Property(e => e.GId).HasColumnName("gId");
entity.Property(e => e.ImageName).HasMaxLength(50);
entity.Property(e => e.ImgProfile).HasColumnName("imgProfile");
entity.Property(e => e.OwnerBillToId).HasColumnName("ownerBillToId");
entity.Property(e => e.OwnerLocationId).HasColumnName("ownerLocationId");
entity.Property(e => e.Rfid)
.HasMaxLength(30)
.HasColumnName("RFId");
entity.Property(e => e.SId).HasColumnName("sId");
entity.HasOne(d => d.BIdNavigation)
.WithMany(p => p.Clients)
.HasForeignKey(d => d.BId)
.HasConstraintName("FK_Clients_Breed");
entity.HasOne(d => d.EnteredByProvider)
.WithMany(p => p.Clients)
.HasForeignKey(d => d.EnteredByProviderId)
.HasConstraintName("FK_EnteredByProvider1");
entity.HasOne(d => d.GIdNavigation)
.WithMany(p => p.Clients)
.HasForeignKey(d => d.GId)
.HasConstraintName("FK_Clients_eqGender");
entity.HasOne(d => d.OwnerBillTo)
.WithMany(p => p.ClientOwnerBillTos)
.HasForeignKey(d => d.OwnerBillToId)
.HasConstraintName("fk_billedToOwner");
entity.HasOne(d => d.OwnerLocation)
.WithMany(p => p.ClientOwnerLocations)
.HasForeignKey(d => d.OwnerLocationId)
.HasConstraintName("FK_locatedAtOwner");
entity.HasOne(d => d.SIdNavigation)
.WithMany(p => p.Clients)
.HasForeignKey(d => d.SId)
.HasConstraintName("FK_Clients_eqSize");
});The foreign keys bId, sIg, and gId all have the word "Navigation"
Note that foreign key EnteredByProvider does not have the word "Navigation" Added.
Not understanding why it gets added and how this model needs to be customized so there is no exception.