I try to databind a list of objects from entity framework to an Ultragrid.
The Grid has a child band wich shows dependent objects. When I enter data in an addnew row of the child band and then navigate somewhere else than to a sibling row, the new object is added to the ObjectSet but not to the EntityCollection. After further navigation the row disappears but the object remains in the object set causing an error when I try to save.
I'm using NetAdvantage 2010.2 and Entity Framework 4.0
Hi,
I haven't had much experience with the Entity Framework, but I know I've seen a lot of posts like this one. It seems like the EntityFramework isn't really very well suited for DataBinding and isn't sending the proper notifications that bound controls need.
I recommend that you search for forums for similar issues, because as I said, there are a number of posts like this discussing the EntityFramework and the problems it has when used as a DataSource.
I have further examined the situation.The child entity was added to the context because of column bound to navigation proerty (pointing to a third EF-type). After hiding this column, the item remains out of the object context (until added to the EntityCollection.)
I also found out: when starting entering a new item it is added to the bindingsource but not to the collection (this is explicilty done in System.Data.Objects.OblectViewEntityCollection<TViewElement, TItemElement>.Add(TViewElement, bool). Only if the Position-property of the CurrencyManager is changed (by navigation to a sibling row), the new item is added to the EntityCollection. But this doesn't happen, if the user firt clicks to another part of the grid. The after reentering the childband, where the item was added, the new row dissapeares.
Con this be solved in anyway?
This certainly sounds like an issue where the EntityFramework objects are not sending notifications to bound controls. So the grid doesn't know anything change until you manually refresh it by changing the active row.
If you can post a small sample project demonstrating this behavior, we can take a look at it and see if there's anything we can do.
Or, you could work around this by calling grid.Rows.Refresh(ReloadData) to manually refresh the grid if you know that something has changed in the data.
I found a solution: in the AfterRowUpdat event, if the updated row is in the childband, I add the ListObject to the collection property of the parent object. Then everything works fine.
I have attached an sample project wich demonstrates the problem.To reproduce: Start the application. Open the childrows of the first row. Enter something in the add new row. Then directly navigate to the other mainrow and then to the first row or its childband. The newly added row will disappear.
The code commented out in the AfterRowUpdate event of the grid shows a possible workaround. If it is uncommented, the application works fine.
For some reasen, the file didn't get attached, so I added it to my profile: EDM_Test.zip
Bad news,
I just found out, that my workaround generates other problems. Now, when navigating only inside the childband, the new entry is presented twice. But this is only a presentation issue, it gets only added once.
I'm really frustated now, can any one help me?