c# - EF, WinForms. Bind navigation property to DataGrid -


i'm following tutorial http://msdn.microsoft.com/pl-pl/data/jj682076. want load particular category context, create datagrid , bind products property of category. want able add, edit, , remove products on datagrid have been trying code:

context.cetegories.where(c => c.categoryid == _category.categoryid ).select(c => c.products).load(); this.productsbindingsource.datasource = _context.categories.local.tobindinglist(); 

where productsbindingsource binding source , datagrid generated designer binding source datasource. how can achieve this? thought load products straight context , bind them datagrid

_context.products.where(c => c.categoryid == _category.categoryid).load(); 

but when want add new product category straight grid there problem fk, because don't know how set new item.

i solved problem myself. earlier code load products category correct. problem code returns object of category type , obtain products navigation property had use binding source category datasource. after use productbingindsource datasource set new bs , datamember property set products navigation property of new bs. allowed me bind products of particular category datagrid.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -