Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i merge these queries into 1
    primarykey
    data
    text
    <p>So i have below queries. I would really like to merge these into 1 query. Next to the fact that this results in an empty collection (which it shouldn't) My brain just imploded when i tried making this into 1 query.</p> <p>So if it's not clear from the code I want to select all horses from a certain user. that have not been signed up for the race that the user is trying to sign up for.</p> <pre><code>var userhorses = (from h in entities.Horses where h.UserId == id select h); var race = (from r in entities.Races where r.Id == id select r).Single(); var runninghorses = (from rh in race.RacingHorses where rh.UserId == id select rh); var nonracinghorses = (from nrh in userhorses from rh in runninghorses where nrh.Id != rh.Id select nrh).ToList(); </code></pre> <p><strong>EDIT</strong></p> <pre><code>public class Horse { [Key] public int Id { get; set; } public int? UserId { get; set; } public virtual User Owner { get; set; } [Required(ErrorMessage = "Name is required")] public string Name { get; set; } public int? GenderId { get; set; } public virtual Gender Gender { get; set; } public int? ColorId { get; set; } public virtual Color Color { get; set; } public int? LegTypeId { get; set; } public virtual LegType LegType { get; set; } public int? CharacterId { get; set; } public virtual Character Character { get; set; } public int Hearts { get; set; } public bool Retired { get; set; } public bool CPU { get; set; } public bool ForSale { get; set; } public int ListPrice { get; set; } public DateTime? Deadline { get; set; } // Parents public int? SireId { get; set; } public virtual Horse Sire { get; set; } public int? DamId { get; set; } public virtual 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; } //Future public virtual ICollection&lt;Race&gt; FutureRaces { get; set; } //RaceResults public virtual ICollection&lt;RaceResult&gt; RaceResults { get; set; } //Training public virtual ICollection&lt;Training&gt; TrainingResults { get; set; } //Bids public virtual ICollection&lt;Bid&gt; Bids { get; set; } public Horse() { ForSale = false; //default value Deadline = null; } } public class Race { [Key] public int Id { get; set; } [Required(ErrorMessage = "Name is required")] public string Name { get; set; } [Required(ErrorMessage = "Purse is required")] public int Purse { get; set; } [Required(ErrorMessage = "Slots are required")] public int Slots { get; set; } public int SlotPrice { get; set; } public DateTime? RaceTime { get; set; } //public int? TrackId { get; set; } //public virtual Track Track { get; set; } public int? OwnerId { get; set; } public virtual User Owner { get; set; } public virtual ICollection&lt;Horse&gt; RacingHorses { get; set; } public virtual ICollection&lt;RaceResult&gt; RaceResults { get; set; } public Race() { SlotPrice = 0; //default value Slots = 8; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload