The problem is that the returned object <asset> contains several foreign keys that are absolutely pointless to the end user to see. What would be the best practice for changing the displayed values to another column in the referenced table?
private void bt_search_Click(object sender, EventArgs e)
{
assetBindingSource.DataSource = ExtendedSearch();
dataGridView.DataSource = assetBindingSource;
}
private IQueryable<asset> BaseSearch()
{
var context = DBEntities.Get();
var results = from a in context.assets
select a;
return results;
}
private IQueryable<asset> ExtendedSearch()
{
var extendedSearch = BaseSearch();
extendedSearch = extendedSearch.Where(x => x.assetType.typeCtgry.ctgry_ofc == parentForm.selectedOffice.ofc_id);
//Other paramaters to add
/*if (!String.IsNullOrEmpty(somestring))
extendedSearch = extendedSearch.Where(x => x.desc.Contains(sometb.Text.Trim()));*/
return extendedSearch;
}
I know I could loop through the results assigning the values to the grid however, I'm sure there must be a more efficient way to handle it.
IQueryable<asset> results = ExtendedSearch();
foreach (asset a in results)
{
//manually adding object attributes to the gridview
a.id
a.desc
a.assetType.txt //foreign key
}

New Topic/Question
Reply



MultiQuote





|