Having been given the all clear to move code from my Page_Loaded method to the constructor (See HERE), i am now encountering errors on my Linq to entities query. It is now causing a nullreferenceexception and i can't figure out why at the moment. See below for the exception location.
public Building()
{
InitializeComponent();
lvBuildings.ItemsSource = App.ocBuildings;
getBuildings();
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
}
private void getBuildings()
{
App.ocBuildings.Clear();
var tehBuildings = from building in App.ents.Buildings
where building.Organisations.OrganisationID == App.selectedOrganisation.OrganisationID
select building;
foreach (Buildings addBuilding in tehBuildings (<--Exception))
{
App.ocBuildings.Add(addBuilding);
}
}
Anyone have any ideas?
Thanks, Kohan.