entity framework - Wpf binding error in datagrid still shows value -
i have wpf application (mvvm style) has datagrid. using entity framework model. in datagrid have column comes value in table. use navigation properties value. when datagrid loads column in question displays right value, there still binding error being generated in output window:
system.windows.data error: 40 : bindingexpression path error: 'product_category' property not found on 'object' ''tracking_stock_ea7f46ec8ad7f155921357aa6714c6c20be807c4760a3b6dfc4fac1954ca8119' (hashcode=49385318)'. null
the object datagrid row bound called tracking_stock has navigation property of product, has navigation property of products_category use product_category.chrprodctgry
here image outline ef design: 
so binding textblock inside datagrid template column follows:
<datagridtemplatecolumn header="category" sortmemberpath="product.product_category.chrprodctgry" tooltipservice.tooltip="category of product" > <datagridtemplatecolumn.celltemplate> <datatemplate> <textblock text="{binding product.product_category.chrprodctgry}" style="{staticresource ftc_detaillabelsub}" width="120" textwrapping="nowrap"/> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> now, works, column can sorted, text in textblock has value supposed to.
question:
why binding error being thrown when works properly?
edit # 1:
i tried remove sort declaration:
sortmemberpath="product.product_category.chrprodctgry"
the binding error still there
edit # 2:
so tried adding isasync=true both textblock , collection binding datagrid itself. textblock value not show until sort category column. in addition binding errors listed above still present, new 1 generated:
system.windows.data error: 17 : cannot 'product_category' value (type 'product_category') 'product' (type 'product_83a5741abc5ee6395b89b7b4b384137e8cf95991ef9918bd4525ef06b774469e'). bindingexpression:path=product.product_category.chrprodctgry; dataitem='tracking_stock_ea7f46ec8ad7f155921357aa6714c6c20be807c4760a3b6dfc4fac1954ca8119' (hashcode=2011918); target element 'textblock' (name=''); target property 'text' (type 'string') targetinvocationexception:'system.reflection.targetinvocationexception: exception has been thrown target of invocation. ---> system.nullreferenceexception: object reference not set instance of object.
edit #3:
sherridan's post got me thinking data not being there when datagrid's collection created database context. went entity framework "get" function , forced include of navigation properties in following 3 ways, none of got rid of binding error:
1
dim trackinglist = await context.tracking_stock.include("product").tolistasync return new observablecollection(of tracking_stock)(trackinglist) 2
dim trackinglist = await context.tracking_stock.include("product.product_category").tolistasync return new observablecollection(of tracking_stock)(trackinglist) 3
dim trackinglist = await context.tracking_stock.include("product").include("product.product_category").tolistasync return new observablecollection(of tracking_stock)(trackinglist)
this can happen if using asynchronous data access operations... could error before data arrives , data bound. had problem , solved adding isasync="true" binding.
update >>>
according first edit question, if removed sort declaration , error still there, not cause of error. search through entire solution product.product_category.chrprodctgry... there must instance of text used in binding somewhere. i'm go home, given time, i'll try take @ later.
Comments
Post a Comment