c#


DatagridView 3rd level Nested Binding


I'm using Entity framework 6 and I'm developing with DBFirst. In the database I have the following structure
Table : product category -> ProductCategory(ProductCategoryID, Name ...)
Table : product -> Product ( ProductID, ProductCategoryID , ...)
Table : products in -> ShelfProducts(ShelfID, ProductID, ... )
stock location
In my Model I have...
class ShelfProduct
{
...
ShelfID {set;get;}
ProductID {set;get;}
Quantity {set;get;}
...
}
class Product
{
...
string Name {set;get;}
virtual ProductCategory {set;get;}
}
class ProductCategory
{
....
Name {set;get;}
}
I'm binding the ShelfProduct in my datagridview and I'm getting the properties ShelfID, ProductID, Quantity. Also I can show Product's Name using additional binding source with DisplayMember,ValueMember properties as 2nd level binding. But When I try to show in datagridview the ProductCategory.Name I can't do it.
I finded a solution but has ppor performance.
My solution is to add directly in the Model, int the class ShelfProduct a getter property like this
class ShelfProduct
{
...
ShelfID {set;get;}
ProductID {set;get;}
Quantity {set;get;}
...
CategoryName
{
get
{
using(DBContext db = new DBContext)
{
ProductCategory pc = db.ProductCategories.Find(this.Product.ProductCategory.ProductCateogryID);
return pc.Name;
}
}
}
}
But the performance increasing dramatically. Also I can't use int he getter directly return this.Product.ProductCategory.Name ObjectDisposed exception occurs.
How can I do ? Any solution ?

Related Links

ASP:Button OnClick event not firing in one specific instance
What is the difference between CellValues.InlineString and CellValues.String in OpenXML?
Passing managed callback to DllImport (ed) function
What is the fastest way to overwrite a file?
Does a method marshalled on the UI Thread need to be thread-safe
WPF Sharing Dependency Properties?
Is it OK to use the request url to store cache keys?
C# Removing trailing '\0' from IP Address string
OnApplyTemplate method does not get called when the custom control is being rendered
Draw Anti-Aliased Text Image like Graphics Software
.NET primitive type addition oddities?
How to unzip compressed files using C#?
C# parsing error, cannot find due to line not existing?
Is floating-point math consistent in C#? Can it be?
Active Directory - Determining unique ID of a domain
How can I show facebook album images on my website using c#?

Categories

HOME
kendo-ui-angular2
stanford-nlp
webvr
livecharts
nltk
docker-compose
aggregate-functions
symfony-3.2
android-webview
pyodbc
runtime
facebook-sharer
osclass
mbed
taxonomy
smooth-scrolling
alert
views
draw2d
autologin
custom-component
git-branch
bug-reporting
inline-assembly
poisson
scrapy-spider
jira-zephyr
deployment-descriptor
knapsack-problem
utc
formtastic
pushpad
concrete5
exacttarget
oracle-nosql
voyager
dropdownbox
scalamock
observer-pattern
remap
spring-cloud-bus
critical-section
wicketstuff
sqlproj
stringbuilder
gevent
scriptengine
instaparse
sbt-proguard
hana-sql-script
computability
sdkman
jsoncpp
roslyn-code-analysis
syncano
eggplant
genome
nfa
xmla
crtdbg.h
qxorm
drools-guvnor
react-os
formbuilder
selenium-grid2
disparity-mapping
parallel-port
scjp
atg-dynamo
behance-api
twitter-finagle
azure-caching
nodeunit
new-operator
autofilter
listpicker
typography
motordriver
nserror
datasheet
commonsware
inserthtml
automapper-2
clgeocoder
discussion-board
digg
qvariant
llblgen
http-response-codes
activescaffold
pitch-shifting
pkcs#7
djangoappengine
memory-consumption

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile