Reputation: 3080
I am having trouble writing up the correct LINQ syntax.
I have a table called eloLists with values ID
(int) and Rank
(string), and a table called Users with a value elo
(int).
I am trying to get a user's rank
by getting their corresponding elo
, which matches the ID
column.
So I have a line like
Temp = Temp + person.summonerID + "," + person.name + "," + person.summoner + "," + myQuery + ",";
where I am try to use myQuery to get this answer. My attempt is this, but I am getting lost..
var myQuery = db.eloLists.Select(x => x.rank.Where(x.ID = db.Users.Select(y => y.elo)));
I am not sure if this even remotely right.
EDIT:
var myQuery = db.eloLists.Where(x => db.Users.Select(y => y.elo).Contains(x.ID)).Select(e => e.rank);
foreach (var person in db.Users)
{
Temp = Temp + person.summonerID + "," + person.name + "," + person.summoner + "," + myQuery + ",";
}
Upvotes: 0
Views: 64
Reputation: 2709
Create a method that returns a string and accept a user object.
public string getrank(User person)
{
var myQuery = db.eloLists.FirstOrDefault(x => x.ID == person.elo));
if(myQuery == null) return string.Empty;
return myQuery.Rank;
}
Then use:
foreach (var person in db.Users)
{
Temp = Temp + person.summonerID + "," + person.name + "," + person.summoner + "," + getrank(person) + ",";
}
Upvotes: 1