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

Memory allocation of string Builder. What happens in memory? StringBuilder vs String
LINQ unable to OrderBy date in specific column?
How do I add a value to a ComboBox selection in C#?
How to turn a generic ASP.net 4.5 MVC 5 login/register into a front facing modal?
Is it possible to update Cors Policy dyamically (OWIN pipeline)
get nearest tens-place number above and below any number
Linq statement : Order by
how to send integer type data in xml
How to read data from Unity3D's prefab file?
How to upload a file using httpwebrequest c#?
Send multi messages via PostAsync within LuisDialog
How to add ComboBox column in XCeed DataGridControl (WPF)
Stream DateTime value,return Epoch value instead of “human” value
Finding a PowerPoint shape using Alternative text without looping through all shapes in C#
ASP.Net Page not loading when locale is en
Use c# variable in Jquery

Categories

HOME
c#
stata
weblogic
bigtable
azure-resource-manager
singleton
hiveql
thermal-printer
sugarcrm
angularjs-directive
multipartform-data
kohana
sequence
cdn
scapy
normals
olap
select2
elastalert
fine-uploader
cakephp-2.0
powerpivot
views
gomobile
minimagick
git-branch
formulas
matlab-gui
procedural-generation
android-wear-2.0
chartist.js
rancher
adobe-captivate
setup-project
git-submodules
ds-5
log4net-configuration
openvms
sdl-2
rythm
stochastic-process
iterm2
area
instances
jquery-inputmask
file-conversion
google-chrome-console
quartz
mtm
php-mongodb
amazon-rds-aurora
text-extraction
qtwebkit
jks
beanshell
playframework-1.x
aws-rds
fckeditor
hellosign
grib
overhead
node.js-client
recursive-query
qt3d
mac-app-store
cosign-api
instaparse
key-value-store
usps
jmh
chomsky-normal-form
wizard
datamodel
encode
kramdown
gulp-cdnizer
serial-communication
jts
properties-file
tess4j
pagecontrol
avd
radgrid
mathics
shunting-yard
sync
sendy
winrun4j
pidgin
fastcgi-mono-server
git-subtree
mixradio
logo-lang
xcode6.1-gm-seed
jfilechooser
randomaccessfile
misfire-instruction
listpicker
kademlia
mosix
nsautoreleasepool
blotter
setcookie
qt5.1
cryptarithmetic-puzzle
tasklist
linear-interpolation
report-viewer2010
facebook-winjs-sdk
zend-validate
digg
lightopenid
quazip
xslt-grouping
large-data-volumes
glassfish-embedded
dojox.gfx
script-tag
expander
hotfix

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App