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

Is there a textboxlist control available somewhere?
How to calculate driving distance between two addresses using Google Maps API?
Draw a circle boundary? [closed]
How to add watermark image in Word file created by C#
What's the difference between .ToConstructor and .ToMethod in Ninject 3?
SQLite: .Net much slower than native?
I want to learn how to program 3D/2D applications (Games) in C#. What should I read? [closed]
Splitting a SQL String per Command
Assigning values to richtextbox [closed]
C# How to use multiple interface implementations
how to create an ASP.NET Web Page to manage folders and files for loading and reading to an external server?
Thread safe calls to windows form are freezing the application
A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property
Is it possible to create bidirectional relationships using only data annotations with EF Code First?
Do not unsubscribe from COMObject events can cause memory leak although I use Marshal.FinalReleaseComObject?
Parent-Child Matrix Chaining/Order Hierarchy

Categories

HOME
optimization
cors
jenkins-pipeline
c++builder
ms-application-insights
sdk
google-search-appliance
unreal-engine4
adroitlogic
mongodb-replica-set
repeater
amazon-data-pipeline
smooth-scrolling
openam
airbnb
include-path
smart-device
cloudformation
multiple-inheritance
csproj
request-uri
dynamics-ax-2012-r3
ocl
mobile-development
selenium3
edsdk
wercker
kubectl
directions
luhn
voyager
odp.net
sampling
mkdir
flex3
repeat
word-wrap
lex
instances
mockserver
socketcluster
mtm
colorbox
pexpect
wufoo
servicebus
angular-fullstack
riemann
programming-pearls
blackberry
lightspeed
qt3d
mongodb-3.3
netlink
jigsaw
django-taggit
firefox-os
fadein
wonderware
windows-kernel
transport
traminer
nexusdb
crystal-reports-7
iphone-6
os.walk
pnunit
xps
nvcc
scidb
zend-db-table
pyxplot
asp.net-4.0
select2-rails
custom-cursor
ios6-maps
django-1.4
nserror
socketasynceventargs
motorola-droid
scsf
utm
cherokee
onunload
azure-appfabric
viewdata
table-valued-parameters
iphone-maps
pitch-shifting
mysql-logic
hp-trim
opengl-to-opengles
projectgen
bootstrap-protocol
vista64
scalable

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