Note that there are some explanatory texts on larger screens.

plurals
  1. POClass Design Question: Union of List<ChildStat> and AllStats
    primarykey
    data
    text
    <p>I have a Player class and a Stat class. The Player class has a List property where PlayerStat has a List and XP properties. I think my design is flawed because I am having trouble doing things that I think should be easy. I want to list out all Players and their XP for all Stats. Below are more details of the classes and the GetCompletePlayerStats method which is what I really don't like. I basically need to list out the XP for all stats for a Player, if the player doesn't have a stat then it should have an XP of zero. Any design help/suggestions would be appreciated.</p> <pre><code>public class Stat : EntityBase{ public virtual string Name { get; set; } public virtual UnitOfMeasure Unit { get; set; } public virtual int UnitXP { get; set; } } public class Player : EntityBase{ public virtual string Name { get; set; } public virtual IList&lt;PlayerStat&gt; PlayerStats { get; set; } public virtual List&lt;PlayerStat&gt; GetCompletePlayerStats(IQueryable&lt;Stat&gt; stats) { var allStats = new List&lt;PlayerStat&gt;(); var playerStatIds = PlayerStats.Select(ps =&gt; ps.PlayerStatistic.Id).ToList(); if (playerStatIds.Count == 0) { allStats.AddRange(stats.Select(stat =&gt; new PlayerStat() {PlayerStatistic = stat, XP = 0})); } else { var zeroStats = stats.Where(s =&gt; !playerStatIds.Contains(s.Id)).ToList(); allStats.AddRange(zeroStats.Select(zeroStat =&gt; new PlayerStat() {PlayerStatistic = zeroStat, XP = 0})); allStats.AddRange(PlayerStats); } return allStats; } } public class PlayerStat : EntityBase{ public virtual Stat PlayerStatistic { get; set; } public virtual double XP { get; set; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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