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:Button OnClick event not firing in one specific instance
What is the difference between CellValues.InlineString and CellValues.String in OpenXML?
Passing managed callback to DllImport (ed) function
What is the fastest way to overwrite a file?
Does a method marshalled on the UI Thread need to be thread-safe
WPF Sharing Dependency Properties?
Is it OK to use the request url to store cache keys?
C# Removing trailing '\0' from IP Address string
OnApplyTemplate method does not get called when the custom control is being rendered
Draw Anti-Aliased Text Image like Graphics Software
.NET primitive type addition oddities?
How to unzip compressed files using C#?
C# parsing error, cannot find due to line not existing?
Is floating-point math consistent in C#? Can it be?
Active Directory - Determining unique ID of a domain
How can I show facebook album images on my website using c#?