Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework 4 difficult query with not mapped property
    primarykey
    data
    text
    <p>I am a newbie in <code>EF</code> and I think that sometimes it's easier to sacrifice the advantage of ORM. But I want to know if there is a way to execute this query using <code>EF4</code>.</p> <p>I have datawarehouse with fact table. Mapping looks like</p> <pre><code> public class GameResult { [Key] public int GameResultId { get; set; } public virtual Competition Competition { get; set; } public virtual CustomDate DateGame { get; set; } public virtual Contender ContenderFirst { get; set; } public virtual Contender ContenderSecond { get; set; } public virtual Location Location { get; set; } public int ScoreContenderFirst { get; set; } public int ScoreContenderSecond { get; set; } public int PrizeStock { get; set; } public int Budget { get; set; } [NotMapped] public int WinCount { get; set; } [NotMapped] public int FailCount { get; set; } [NotMapped] public int DeadHeatCount { get; set; } [NotMapped] public int CountGames { get; set; } } </code></pre> <p>And query on <code>sql</code></p> <pre><code>select Contenders.Name, sum((Case when (ScoreContenderFirst &gt; ScoreContenderSecond) then 1 else 0 end)) as wins, sum ((Case when (ScoreContenderFirst = ScoreContenderSecond) then 1 else 0 end)) as equals, sum((Case when (ScoreContenderFirst &lt; ScoreContenderSecond) then 1 else 0 end)) as fail, COUNT(GameResults.GameResultId)as countGames from GameResults inner join Contenders on GameResults.ContenderSecond_ContenderId = Contenders.ContenderId where GameResults.ContenderFirst_ContenderId = 42 group by Contenders.Name UNION select Contenders.Name, sum((Case when (ScoreContenderFirst &lt; ScoreContenderSecond) then 1 else 0 end)) as wins, sum ((Case when (ScoreContenderFirst = ScoreContenderSecond) then 1 else 0 end)) as equals, sum((Case when (ScoreContenderFirst &gt; ScoreContenderSecond) then 1 else 0 end)) as fail, COUNT(GameResults.GameResultId)as countGames from GameResults inner join Contenders on GameResults.ContenderFirst_ContenderId = Contenders.ContenderId where GameResults.ContenderSecond_ContenderId = 42 group by Contenders.Name </code></pre> <p>This <code>sql</code> query means (I want to get game results of a particular team versus other teams (number of games that the particular team is winner, and number of games where the particular team is looser) )</p>
    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.
 

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