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
c# SerialPort DataReceivedHandler not being called for every event.
c# identity get logged in user in api controller
Query list of partitions (and/or partition key values) in DocumentDB
Create multiplatform Nuget from same project files
Selenium testing. Simple exception if there's an error on screen
Syntax Error while passing numeric column name in my update query of sql server in c#
How to trim the end of a string after the first occurrence of a char C#
Link to a file that will later be published c#
C#: call a batch file and skip “press any key to continue”
Getting filenames from azure storage given url folder path
C# Sqlite Error on SQLiteBlob.Create
Different behavior in ShiftRows with .xls and .xlsx in NPOI 2.3.0
Error handling for Tasks inside Task.WhenAll
Virtual property is not being set to an instance for product being added to shopping cart
Is printing of dashed lines in WPF wrong?
UniqueBody is not very unique?