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.Net MVC Tutorial Unit Tests - Steve Sanderson
no update on sql server database. No errors just no results
LoginAsync missing
linq to entities contains does not work
Entity Framework object not persisting/saving to database table
Orchard CMS - Alternates
How to load/unload Word Add-in programatically?
Can Process.HasExited be true for the current process?
Adding new content to a session
Create Secondary tile without displaying the Pin to Start flyout in windows 8/RT [closed]
Simplest way to serve dynamic content with .net (& preferably iis) without any form of asp.net / WCF / built in technology
How to select current dates from current month
How to replace part of the path?
Getting a list of strings via LINQ
search keywords in google through c# window application
Autoresize Listview Columns on content update

Categories

HOME
grizzly
nagios
coordinates
esxi
xss
msbi
ms-access-2010
browser-cache
uml-designer
yuv
foreach
meson-build
restheart
olap
wowza
watson-dialog
saucelabs
bookmarklet
facebook-marketing-api
pylint
amazon-data-pipeline
cucumberjs
jquery-easyui
beacon
angular2-pipe
windows-mobile
ballerinalang
multiple-inheritance
dynamics-ax-2012-r3
cqlsh
akamai
ibm-bpm
choco
imdb
jcr
android-scrollview
angularjs-resource
sampling
outlook-2010
motion
quartz
compiler-warnings
datagridviewcombobox
apiman
taiga
line-endings
yank
easyquery
import.io
ng-class
e4
richtext
business-catalyst
timex
qt3d
spring-social-twitter
jira-agile
mate-desktop
init
diameter-protocol
usps
archiva
web-optimization
factorization
nonblocking
event-tracking
cloud-storage
glog
screen-lock
skview
nfa
grunt-contrib-connect
famous-engine
system.net
redmine-plugins
drawable
ccmenuitem
yandex-api
object-oriented-database
cvi
starling-framework
boofcv
db2-connect
xcode6.1-gm-seed
xcode5.1
grape-api
pechkin
aspnet-compiler
cab
extensibility
jython-2.5
qmainwindow
system.transactions
database-restore
orchestration
hypertable
aspmenu-control
bash4
rjs
xpolog
hwnd
xhtmlrenderer
zipstream
versions
unauthorized

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile