It very well could be my UI Design.
I have a DataGridView that displays some columns from an entitycollection via a bindingsource so that the user can select which record they want to edit.
The entitycollection is popluated with fields on the FieldsOnRelatedFields Tab and uses a prefetchPath to fetch those related fields.
The user interface has comboboxes in listmode that has a list of the available related fields so that the user can change the related field when editing the record. The combo box has the DisplayMember set to the description and the ValueMember set to the foreign key.
This is using DataBound controls and all of that works fine
The problem is that when the user saves a new record and the saved record is retrieved by the SaveEntityCollection, the related entities (which were not changed, the foreign key was set on the new entity) are not retrieved to display the related description.
As a result, I have to code the following three lines after the SaveEntityCollection.
I'm sure I am just being lazy, it just seems that once an EntityCollection is retrieved with a PrefetchPath, the PrefetchPath should be stored with the EntityCollection object and optionaly reused whenever the EntityCollection is persisted.
Private Sub SavePrice()
Using adapter As IDataAccessAdapter = DataBase.GetAdapter()
Try
Me.BSFuelPricesForDate.EndEdit()
adapter.SaveEntityCollection(Me.ecFuelPrice, True, True)
Dim ft As EntityClasses.FuelPriceEntity = CType(Me.BSFuelPricesForDate.Current, EntityClasses.FuelPriceEntity)
adapter.FetchEntity(ft, Me.GetFuelTypePrefetchPath)
Me.BSFuelPricesForDate.ResetBindings(False)
Catch ex As SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException
DisplayError.Show(Me, ex.Message, ex)
End Try
End Using
End Sub
Private Function GetFuelTypePrefetchPath() As IPrefetchPath2
Dim pp As IPrefetchPath2 = New PrefetchPath2(CType(EntityType.FuelPriceEntity, Integer))
pp.Add(EntityClasses.FuelPriceEntity.PrefetchPathFuelPriceSource)
pp.Add(EntityClasses.FuelPriceEntity.PrefetchPathFuelType)
pp.Add(EntityClasses.FuelPriceEntity.PrefetchPathUnitsOfMeasure)
Return pp
End Function