This is a migrated thread and some comments may be shown as answers.

DataForm and QueryableDataServiceCollectionView

6 Answers 150 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
HCT-CERT
Top achievements
Rank 1
HCT-CERT asked on 18 Sep 2012, 08:03 AM
Hi,

In one of my projects,I use WCF data services for querying the database,and use GridView, and DataForm for viewing and editing data.When the user double click on a row, I create a filtered DataServiceQuery (e.g. ID=55) and use it to initialize a QueryableDataServiceCollectionView<T> which I then assign to the RadDataForm ItemsSource.I can successfully add ,delete, and edit records by calling SubmitChanges() on the ItemsSource (which is of type QueryableDataServiceCollectionView<T>),
 but I am facing other difficulties:

1-I have an entity Sim which has a 1 to many association property called Installations. When clicking Cancel while editing or inserting in the DataForm, I get the following error which seems to be caused by the DataForm trying to set a value on the Installations property.

Setting an instance of DataServiceCollection to an entity property is disallowed if the instance is already being tracked. Error occurred on property 'Installations' for entity type 'TDS.DeviceManagementDataService.Sim'.


2-When I open an existing record for editing,and click the 'insert' button,fill-in the form,and click save,the record is saved but the form goes back and display the record that was being edited earlier.

My last question is: what is the best way of databinding a RadDataForm when working with WCF data service ?

GridView Double Click Code:

private void SimsGridView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {          
            SimView view = new SimView();
            QueryableDataServiceCollectionView<Sim> dataContext = new Telerik.Windows.Data.QueryableDataServiceCollectionView<Sim>(db, db.Sims.Where(i => i.ID == SimsGridView.GetSelectedItem<Sim>().ID).ToDataServiceQuery<Sim>());
            dataContext.PageSize = 100;
            dataContext.AutoLoad = true;
            view.DataContext = dataContext;
            view.Show();
            view.Focus();
            
        }

SimView Window:

<telerik:RadDataForm x:Name="rdfSim" ItemsSource="{Binding}" AutoGenerateFields="False"  HorizontalAlignment="Stretch"  VerticalAlignment="Stretch"
            ReadOnlyTemplate="{StaticResource MyTemplate}" NewItemTemplate="{StaticResource MyTemplate}"
                                 EditTemplate="{StaticResource MyTemplate}" EditEnded="rdfSim_EditEnded"
                                  CommandButtonsVisibility="All"   ValidatingItem="rdfSim_ValidatingItem" DeletedItem="rdfSim_DeletedItem">         
 
        </telerik:RadDataForm>



Thanks in advance

Madani

6 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 21 Sep 2012, 10:24 AM
Hi Madani,

We have recently encountered the issue that you are describing in pt. 1 and we are already working on a fix. As for the behavior that you have described in pt. 2, we will need some more time to test similar scenarios. I will come back to you as soon as we can give you appropriate feedback. As for the last inquiry of your list, you can refer to RadDataServiceDataSource's documentation (MVVM article) and demos. There should not be any specific diferences when it is used alongside RadDataForm.

Regards,
Ivan Ivanov
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
HCT-CERT
Top achievements
Rank 1
answered on 27 Sep 2012, 04:33 PM
Thanks you Ivan.Please let me know when you are planing to release a fix for this (especially item number 1).We have a client demo on Sunday and all our forms are generating errors when user clicks 'Cancel'.

It Will be nice if you can show me a workaround for item number 1 before the next fix.

Thanks

Madani
0
Ivan Ivanov
Telerik team
answered on 02 Oct 2012, 02:35 PM
Hello,

This fix will possibly be officially available for Q3 2012. Unfortunately currently there is not acceptable workaround. May I ask you whether you are using auto-generated fields and if so, is the "Installations" property canceled in the AutoGeneratingDataField event, by any chance? I will try to provide you a pre-release version of this fix, for testing purposes only, so that I will need this info.

Kind regards,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
HCT-CERT
Top achievements
Rank 1
answered on 16 Oct 2012, 12:56 PM
Hi Ivan,

I am not using any auto generated fields.The bug is in the method CancelEditCore which loops through all properties and tries to set them back to initial values.This is fine for primitive and object based properties,but it throws exception if the property is of type DataServiceCollection<T>.This is the case with all child entity properties (e.g. Installations).

I also noticed that if the current item implements IEditableObject, the method IEditableObject.CancelEdit() is called twice:one time through this.FormViewModel.Items.CancelEdit() =>QueryableCollectionView .CancelEdit()=>QueryableCollectionView 
CancelEditItem(this.CurrentEditItem)=>ExecuteAs<IEditableObject>(item, i => i.CancelEdit())

and the second time through :

if (currentEditableObject != null)
            {
                currentEditableObject.CancelEdit();
                this.IsItemChanged = false;
            }

My workaround for the moment is by calling RejectChanges() on the ItemsSource property which is of type QueryableDataServiceCollectionView<T>   .This works fine so far.

Thanks

Madani



0
Ivan Ivanov
Telerik team
answered on 19 Oct 2012, 01:03 PM
Hi Madani,

Please, excuse me for the delayed reply. The exception in CancelEditCore is being processed with our latest internal build and later versions. You can either test it with it, or the Q3 release. As a side note, please let notify you that now you can disable the PropertyChanged-based cancelling and rely exclusively on IEditableObject, by setting the new RadDataForm's property EnablePropertyChangedBasedCancelto false.

Regards,
Ivan Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Chris
Top achievements
Rank 1
answered on 26 Oct 2012, 09:35 AM
Hi,

The same issue exists if you are using Entity Framework directly in the client. If you try and cancel while editing it will throw an exception as the DataForm is trying to reset the backing fields on the underlying object.

rgds
Chris
Tags
DataForm
Asked by
HCT-CERT
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
HCT-CERT
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Share this question
or