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

How to split 3DES key and calculate KCV in C#?
How to display list items on console window in C#?
Encrypt text using Caesar cipher C# [duplicate]
Proxy GZIP Compression
Getting SQL to work from C# with Dates
Store Enum as Char with Dapper
Drag and Drop Windows Forms: Controls dissapear after dragging
What is the best way to count all instances of a single process running under a particular user logon?
C# Security Protocol Specification
Ajax Dropdownlist using cascading dropdownlist in asp.net
Adding textbox value with button in C#
How to show the tooltip without any time duration?
How can i hide in game view a ui button and show the button when pressing the escape key?
TCP Connection. best way to handle multiple connections [duplicate]
Send POST request with Image from Unity3D
How to make default Password Reset functionality work in ASP.NET Core

Categories

HOME
leaflet
virtual-machine
cluster-analysis
jenkins-pipeline
postgresql-9.3
apache-storm
reference
readdir
gaussian
spotfire
watson-iot
pandoc
checkpoint
procmon
country-codes
install
scapy
olap
jcodemodel
jpql
google-search-appliance
distinct
expo
mbed
jinja2
sha1
loss
owncloud
pylint
hapijs
draw2d
lotusscript
multipart
fastboot
pumping-lemma
smart-device
tftp
formtastic
cloudformation
restangular
pypy
r-factor
semantic-ui-react
folder
paper-trail-gem
edsdk
boost-log
lines
restler
border-layout
kdevelop
mongoid5
word-wrap
gem-fury
server-side-swift
file-descriptor
aura-framework
autodesk-data-management
definition
superclass
spring-ide
google-chrome-storage
automapper-4
react.rb
printer-control-language
ios-keyboard-extension
group
msiexec
firebase-job-dispatcher
joystick
require-handlebars
shtml
laterjs
mod
trendline
dynamics-nav
gulp-cdnizer
database-project
updating
exchange-server-2007
tokudb
tinymce-plugins
system.diagnostics
javadb
grunt-contrib-connect
step
amzi-prolog
hotlinking
sendy
smartxls
satisfiability
nativequery
autofilter
adabas
ekevent
maven-javadoc-plugin
tlbimp
outlook-object-model
github-archive
diazo
joomla1.7
soapexception
mismatch
moss2007-security
marathontesting
http-response-codes
nstoolbar
for-xml
authkit
httpbrowsercapabilities

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