我有一张表Users
和一张表PastElo
。我正在尝试创建一个新变量(s1rank
)来存储User
值,该值在select
语句期间在PastElo中引用。
即。 (表格缩小了)
---User---
id: int (PK)
name: string
elo: int (FK -> id in PastElo)
---PastElo---
id: int (PK)
rank: string
rank
是用户elo
的名称,我正在尝试跟踪elo
的字符串名称,或者至少能够在返回{List
之后访问它所有用户中的{1}}。
var result = db.Users.Select(x => new { x.name, x.email, x.summoner,
x.birthday,x.school, x.bio, x.champ1, x.champ2, x.champ3,
x.elo, x.facebook, x.rank,x.role1, x.role2, x.s1elo, x.s2elo,
x.s3elo, x.s4elo, x.steam, x.stream, x.summonerID,
//my attempt to get rank's value for elo's int
s1rank = x.PastElo.Rank.Select(x.s1elo == x.PastElo.ID) }
).ToList();
之后发生,然后传递给AngularJS服务。有没有一种简单的方法来获取用户的elo
值的字符串/名称?
所以当我说{{users.s1rank}}
时,我想要保存用户的elo排名的字符串名称,而不是elo的int
值。
答案 0 :(得分:0)
对于那些寻找答案的人,我做的是以下内容,以便从其他几个包含int
值/名称的表中获取FK string
。
var query = from users in db.Users
join s1 in db.PastEloes on users.s1elo equals s1.ID
join s2 in db.PastEloes on users.s2elo equals s2.ID
join e in db.eloLists on users.elo equals e.ID
join r in db.rankLists on users.rank equals r.ID
select new
{
elo1 = s1.Rank,
elo2 = s2.Rank,
elo = e.rank,
rank = r.rank,
sortElo = users.elo,
sortYear = users.school,
users.name,
users.email,
users.summoner,
users.birthday,
};