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

WCF Binding SOAP 1.1 requests with both “application/xml” and “text/xml” ContentTypes
“A generic error occurred in GDI+” while using MeasureString
as.net repeater does not contain a definition for repeater
My Windows Service can't start
How to display entered string from textbox in ordered list in c#?
Exporting datagridview to excel file failed
Process.Start will not work when invoked from Task Scheduler on server
WPF change ListView scroll speed
Iteration over XML returns Same Node Over & Over
Making a textbox hang outside of WPF application c# [duplicate]
json.Net save to file
Why does the main thread's output come first in C#?
Unity vs iOS and for loops not executing the same way?
Is it possible to create a signed email with an opaque signature using MimeKit?
How to create controls dynamically in master's child pages in c#? [duplicate]
How can I combine information in two different classes to show the result in a ListBox?

Categories

HOME
postgresql
mobile
casting
microcontroller
phantomjs
ubuntu-14.04
country-codes
meson-build
scapy
sahi
ionic-native
ejb-3.0
ethereum
unreal-engine4
desktop-application
oxid
opendaylight
web-worker
css-float
openam
airbnb
hl7-fhir
typedef
mattermost
ng-tags-input
concatenation
apdu
windowserror
sqldependency
ipython-parallel
jboss-arquillian
language-detection
log4net-configuration
flickr
android-scrollview
console.readline
anypoint-studio
mockserver
gem-fury
azure-web-roles
wicket-tester
contenteditable
qt-quick
smooth-streaming
result
gradlew
risc
ocamlbuild
runner
g77
hdpi
ionic2-select
pyopenssl
standard-error
google-scholar
android-tabs
papyrus
indoor-positioning-system
x12
hdr
xcode7.1
android-xmlpullparser
nimbus
shtml
jmh
nugetgallery
periodic-processing
music-player
yfiles
newlib
php-gd
glog
targetprocess
fileinputstream
beagleboard
indices
qxorm
random-access
jsonschema2pojo
go-gin
selenium-grid2
pytz
nest-initiative
ccmenuitem
parallel-port
disabled-control
episerver-7
lettuce
nodeunit
nvcc
netbeans-plugins
xcode6.1-gm-seed
tlbimp
listpicker
bho
servicemanager
openafs
github-archive
digg
response-time
mass-emails
p4.net
linq-to-mysql
carbon-emacs
file-storage
file-icons
vista64
stackless

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App