I'm trying to fill my DataGrid
dgGoals.ItemsSource = GetGoals(new int[] { 1, 2, 3 });
This is the In Memory object that has data loaded from a different process
static ObservableCollection<Goal> goals = new ObservableCollection<Goal>();
I tried using this example Linq version of SQL "IN" statement but both the lambda and LINQ statements are returning null when it should be 100 records.
public static ObservableCollection<Goal> GetGoals(int[] selectedGoalKey)
{
//goals has 170 records at this point
//selectedGoalKey has 3 items (1,2,3)
//goals has 100 records with Goal_Key of 1,2 or 3
//Returns null
return goals.Where(f => selectedGoalKey.Contains(f.Goal_Key)) as ObservableCollection<Goal>;
//Returns null
return (from g in _Goals
where selectedGoalKey.Contains(g.Goal_Key)
select g) as ObservableCollection<Goal>;
}
EDIT Fixed and now works
public static IEnumerable<Goal> GetGoals(int[] selectedGoalKey)
{
//goals has 170 records at this point
//selectedGoalKey has 3 items (1,2,3)
//goals has 100 records with Goal_Key of 1,2 or 3
//Now returns 100 records
return goals.Where(f => selectedGoalKey.Contains(f.Goal_Key));
//Now returns 100 records
return (from g in _Goals
where selectedGoalKey.Contains(g.Goal_Key)
select g);
}
ObservableCollection<Goal>? That's your issue. Instead pass theIEnumerableto theObservableCollection<Goal>constructor.