我是新手,EF
我认为有时牺牲 ORM 的优势更容易。但我想知道是否有办法使用EF4
.
我有带有事实表的数据仓库。映射看起来像
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; }
}
并查询sql
select
Contenders.Name,
sum((Case
when (ScoreContenderFirst > ScoreContenderSecond) then 1
else 0
end)) as wins,
sum ((Case
when (ScoreContenderFirst = ScoreContenderSecond) then 1
else 0
end)) as equals,
sum((Case
when (ScoreContenderFirst < 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 < ScoreContenderSecond) then 1
else 0
end)) as wins,
sum ((Case
when (ScoreContenderFirst = ScoreContenderSecond) then 1
else 0
end)) as equals,
sum((Case
when (ScoreContenderFirst > 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
此sql
查询的意思是(我想获取特定球队与其他球队的比赛结果(特定球队获胜的比赛数量,以及特定球队较松的比赛数量))