I have been trying to bind a variable to WPF. I am using LINQ to get the data. The criteria is a unique int type and returns a single row of data that has 30 columns, of which there are several different types that need to be returned.
I am getting this error InvalidOperationException Class, but I can't figure out how to fix this?
This is what I have thus far,
internal class DatabaseQueries
{
public static IEnumerable<int> ModValues(DatabaseDataContext database, int staffNo)
{
return database.Staff_Mod_TBLs
.Where(staff => staff.Staff_No == staffNo).Cast<int>().ToList();
}
}
This is the code that set the variable,
int staffNumber = 192356;
var modTblValue = DatabaseQueries.ModValues(sql, staffNumber);
And the XAML, (for some reason I can't post all the XAML, so this is an abbreviated snip of code.)
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock FontWeight="Normal" Text="{Binding Path=modTblValue, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
modTBlValueas a property. binding only works with properties..Cast<int>()- where did you see that? Go and learnSelect.Select,Whereare pretty basic things, you can't use LINQ without knowing at least the basic constructs.The process of learning something you don't already know. If I knew everything there was to know about LINQ, I am sure I would not be in the pickle. I am sure you can relate to when you wrote your firstHello worldline of code? So you suggest using select? I followelled the error message that said I was missing a cast, that is why that is in there. I have literally searched dozens of pages to get where I am right now.