I used LINQ to query two tables and showed the result in a var Spelers. This works fine but now I want to re-use this query outside the method after first clearing the var. I searched all resources known to me but couldn't find a solution.
The query Spelers uses the ObserverableCollections speler and golfclub. I try to create an app for my C# exam and I am c# novice. I hope someone can help me with this because I want all queries to be public accessible.
public void JoinData()
{
var Spelers = (from spel in speler
join club in golfclub
on spel.ClubId equals club.Id
select new
{
Id = spel.Id,
Voornaam = spel.Voornaam,
Achternaam = spel.Achternaam,
Handicap = spel.Handicap,
Telefoon = spel.Telefoon,
Email = spel.Email,
Homeclub = club.Naam,
ClubId = spel.ClubId,
TeamId = spel.TeamId,
PuntenVoor = spel.PuntenVoor,
PuntenTegen = spel.PuntenTegen
}).ToList();
if (Datagrid.ItemsSource == null)
{
Datagrid.ItemsSource = Spelers;
}
}