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

RadGridView with Telerik.OpenAccessContext as ItemsSource not saving/deleting rows

1 Answer 60 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Robin
Top achievements
Rank 1
Robin asked on 20 Feb 2014, 08:42 AM
Hello,

Our company is trying to set up a pretty basic WPF Program with a code-first database (FluentModel) and a RadGridView to edit/add/delete data.
So far, everything works, except for the deleting/adding data part. Editting works just fine.

It's a MSSQL Database that gets all of its mapping and fields from Telerik's FluentMetaDataSource .

The problem, I think, lies in the fact that getting data using OpenAccessContent.GetAll<>() returns an IQueryable.
When using this IQueryable, the button to add a new row ("Click here to add new item") simply doesn't work.
A workaround for this is returning an IList instead using OpenAccessContent.GetAll<Type>().ToList() .
Using this as an ItemsSource instead makes it possible to edit existing items (and they can get retreived using our FluentModel's GetChanges().GetUpdates<Type>() method. However, GetInserts<Type>() and GetDeletes<Type>() is always empty, even though we visually see the data in the RadGridView. The changes simply don't go through.

Am I missing a very simple step? I certainly hope so.

01.<controls:RadGridView ItemsSource="{Binding Units}"
02.                      x:Name="UnitGridView"
03.                      CanUserFreezeColumns="False"
04.                      NewRowPosition="Top"
05.                      RowIndicatorVisibility="Collapsed"
06.                      GroupRenderMode="Flat"
07.                      ShowColumnFooters="False"
08.                      ShowColumnHeaders="True"
09.                      CanUserSortColumns="True"
10.                      ShowColumnSortIndexes="True"
11.                      ShowGroupFooters="False"
12.                      ShowGroupPanel="False"
13.                      GridLinesVisibility="Both"
14.                      BorderBrush="Transparent"
15.                      BorderThickness="0"
16.                      RowStyle="{StaticResource RowStyle}"
17.                      SelectedItem="{Binding SelectedUnit, Mode=TwoWay}"
18.                      AutoGenerateColumns="False"
19.                      SelectionUnit="FullRow">
20. 
21.    <controls:RadGridView.Columns>
22.        <controls:GridViewDataColumn DataMemberBinding="{Binding Id}" IsReadOnly="True"/>
23.        <!-- Fields ... -->
24.    </controls:RadGridView.Columns>
25.</controls:RadGridView>

01.public class FluentModel : OpenAccessContext, IFluentModelUnitOfWork
02.{
03.    private static string connectionStringName = @"connectionId";
04.    public static String ConnectionString{get { return ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString; }}
05. 
06.    private static readonly BackendConfiguration backend = GetBackendConfiguration();
07.    private static readonly MetadataSource metadataSource = new FluentModelMetadataSource();
08. 
09.    #region Lists
10. 
11.    public IList<UnitType> UnitTypes
12.    {
13.        get { return GetAll<UnitType>().ToList(); }
14.    }
15. 
16.    public IList<Address> Addresses
17.    {
18.        get { return GetAll<Address>().ToList(); }
19.    }
20. 
21.    public IList<Project> Projects
22.    {
23.        get { return GetAll<Project>().ToList(); }
24.    }
25. 
26.    public IList<Unit> Units
27.    {
28.        get { return GetAll<Unit>().ToList(); }
29.    }
30. 
31.    #endregion
32. 
33.    #region constructors
34.    public FluentModel()
35.        : base(connectionStringName, backend, metadataSource)
36.    { }
37. 
38.    public FluentModel(string connection)
39.        : base(connection, backend, metadataSource)
40.    { }
41. 
42.    public FluentModel(BackendConfiguration backendConfiguration)
43.        : base(connectionStringName, backendConfiguration, metadataSource)
44.    { }
45. 
46.    public FluentModel(string connection, MetadataSource metadataSource)
47.        : base(connection, backend, metadataSource)
48.    { }
49. 
50.    public FluentModel(string connection, BackendConfiguration backendConfiguration, MetadataSource metadataSource)
51.        : base(connection, backendConfiguration, metadataSource)
52.    { }
53.    #endregion
54. 
55.    public static BackendConfiguration GetBackendConfiguration()
56.    {
57.        BackendConfiguration backend = new BackendConfiguration();
58.        backend.Backend = "MsSql";
59.        backend.ProviderName = "System.Data.SqlClient";
60.        return backend;
61.    }
62.}

Summary: Data CAN be editted and gets passed to the context's (FluentModel) GetChanges().GetUpdates() list. Inserts/Deletes SEEM to work VISUALLY in the RadGridView, but rows do NOT actually get inserted/deleted and the GetInserts() and GetDeletes() lists are always EMPTY. What could be the cause of this?

Thank you for taking your time to read and help

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 25 Feb 2014, 09:51 AM
Hi,

Indeed, the problem comes from the fact that you are providing IQueryable data source. IQueryable does not support adding new items (in order to add new items your data source should implement IList interface) or deleting existing ones. You could filter this collection with LINQ queries when needed. 

You could create a List collection out of your original one or wrap it in another collection, and set the RadGridView.ItemsSource to work it with instead. 

Regards,
Didie
Telerik
Tags
GridView
Asked by
Robin
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or