Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6644401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:09:47+00:00 2026-05-26T00:09:47+00:00

Here is my model public class Horse { public int HorseId { get; set;

  • 0

Here is my model

public class Horse
{
    public int HorseId { get; set; }
    public string Name { get; set; }
    public string Gender { get; set; }
    public LegType LegType { get; set; }
    public Character Character { get; set; }
    public int Hearts { get; set; }
    public bool Retired { get; set; }
    // Parents
    public Horse Sire { get; set; }
    public Horse Dam { get; set; }
    // Internals
    public int Stamina { get; set; }
    public int Speed { get; set; }
    public int Sharp { get; set; }
    // Special
    public int Dirt { get; set; }
    // Externals
    public int Start { get; set; }
    public int Corner { get; set; }
    public int OutOfTheBox { get; set; }
    public int Competing { get; set; }
    public int Tenacious { get; set; }
    public int Spurt { get; set; }
    //Races
    public virtual ICollection<Race> RaceResults { get; set; }
    //Training
    public virtual ICollection<Training> TrainingResults { get; set; }
}

public class Race
{
    public int RaceId { get; set; }
    public int Favorite { get; set; }
    public LegType LegType { get; set; }
    public int Players { get; set; }
    public DateTime Split { get; set; }
    public DateTime Final { get; set; }
    public int Position { get; set; }

    public virtual int TrackId { get; set; }
    public virtual Track Track { get; set; }

    public virtual int LinkedHorseId { get; set; }
    public virtual Horse LinkedHorse { get;set; }
}

public class Training
{
    public int TrainingId { get; set; }
    public string Type { get; set; }
    public string Result { get; set; }
    public string Food { get; set; }
    public int Start { get; set; }
    public int Corner { get; set; }
    public int Outofthebox { get; set; }
    public int Competing { get; set; }
    public int Tenacious { get; set; }
    public int Spurt { get; set; }

    public virtual int LinkedHorseId { get; set; }
    public virtual Horse LinkedHorse { get; set; }
}

public class Track
{
    public int TrackId { get; set; }
    public string Name { get; set; }
    public int Distance { get; set; }
    public bool G1 { get; set; }
    public int Prize { get; set; }
}

And here is my fluent API code.

public class HorseTracker : DbContext
{
    public DbSet<Horse> Horses { get; set; }
    public DbSet<LegType> LegTypes { get; set; }
    public DbSet<Character> Characters { get; set; }
    public DbSet<Training> TrainingResults { get; set; }
    public DbSet<Track> Tracks { get; set; }
    public DbSet<Race> Races { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Race>()
            .HasRequired(r => r.LinkedHorse)
            .WithMany(h => h.RaceResults)
            .HasForeignKey(r => r.LinkedHorseId);

        modelBuilder.Entity<Training>()
            .HasRequired(t => t.LinkedHorse)
            .WithMany(t => t.TrainingResults)
            .HasForeignKey(t => t.LinkedHorseId);

        modelBuilder.Entity<Race>()
            .HasRequired(r => r.Track)
            .WithMany()
            .HasForeignKey(r => r.TrackId)
            .WillCascadeOnDelete(false);
    }
}

I keep getting this error:
Unable to determine the principal end of an association between the types ‘DOCCL.Models.Horse’ and ‘DOCCL.Models.Horse’. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.

Any clue what i’m doing wrong.
I’ve been playing around with no foreign keys. making one of the required lists optional.
they all result in different errors.
mostly saying that the relation needs to be a 1:1 relation.
And once it said that it had a non nullable field.

I made that nullable int? and then i got the first error again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:09:47+00:00Added an answer on May 26, 2026 at 12:09 am

    I think you need to setup self-referencing relationships manually (specifically, the Horse class properties Sire and Dam are causing an issue).

    Try this (in the answer):

    What is the syntax for self referencing foreign keys in EF Code First?

    You could add two more int IDs representing the foreign keys (SireId, DamId).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model public class Foo{ public int Id{get;set;} public string Name {get;
Here's my model public class Movie { public int MovieID { get; set; }
Here is my model: public class NewsCategoriesModel { public int NewsCategoriesID { get; set;
Here is a model: Public class Person { [Key] Public int PersonId { get;
Model: public class Model { public ItemType Type { get; set; } public int
I have this model: public class Package { public string CustomerName { get; set;
I have following model: public class FormularModel { [Required] public string Position { get;
Consider the following model: public class BandProfileModel { public BandModel Band { get; set;
ok say i have the following model: public class bar{ public string bar {get;
Very simple situation, here is my model: public class Comment { [Required] public string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.