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

Convert vb.net Linq to c# Group by, with sum & max & min [closed]
It is ok to store a Thread in a static variable?
How to copy data from Windows phone app internal storage to SD card or phone
Main thread freezes when waiting for Web service synchronously in Windows Phone Silverlight Application 8/8.1
ASP .NET GridView not displaying rows
SQL stored procedure not returning all SELECT statements
C# Calculate the image scroll with scrollbar
stream audio and video data separately
Azure Active Directory Authentication with Azure Mobile Services Failed
Xamarin Parse Component refresh current user
How to use Automapper to map an object to an interface at a different level?
ASP.Net C# equivalent to Coldfusion cfoutput GROUP
HtmlAgilityPack convert XPath query to LINQ
How to assign System.Drawing.Color to Microsoft.Office.Interop.Excel.ColorFormat
Construct a list of wpf Hyperlink elements from an XML source file using Linq
Exception while using Regex with richtextbox in C#

Categories

HOME
pact
drupal
google-cloud-pubsub
kendo-ui
gap-system
dynamic
skypedeveloper
sugarcrm
comments
jquery-select2
browserstack
revit-api
ephesoft
yacc
ldap-query
solidity
drush
pylint
tcpdf
bootstrap-accordion
ballerinalang
uibarbuttonitem
meteor-accounts
pypy
folder
jboss-arquillian
arp
andengine
lines
akamai
dom4j
outlook-2010
rtsp
const
stdin
motion
mybatis-generator
wicket-tester
socketcluster
contenteditable
angular-fullstack
ack
qtwebkit
spring-ide
beanshell
cancan
bioperl
easy-thumbnails
universe
change-password
hfp
mod
dcast
wonderware
jcomponent
notice
joomla3.3
dcg
grails-3.0.9
fileinputstream
system.diagnostics
gmaps4jsf
firebase-tools
optimistic-locking
fiware-health
quickfixn
crystal-reports-7
livescript
triplestore
mvcgrid
behance-api
elixir-framework
html5-filesystem
netbeans-plugins
nop
randomaccessfile
kendo-window
typography
azure-scheduler
removeall
magicsuggest
gmail-imap
brew
database-restore
screensharing
inflate
mail-gem
expresso-store
php-gettext
ios6-maps
nserror
eeprom
scsf
peoplepicker
mismatch
lightopenid
database-agnostic
bootstrap-protocol

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