12 Answers, 1 is accepted
Have you tried our demos for RadEntityFrameworkDataSource?
Kind regards,Vlad
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.

Hello, thank you very much for the reply. I did not notice the Lode and Submit Button in the EntityFrameworkDataSource.WPF project :-|.
But how can I bind the RadEntityFrameworkDataSource in my ViewModel and in general, all the events which are mentioned in the tutorial and the documentation, how do I fetch them in the VM? For example the CellValidating event?
Best regards
You could bind the GridView to a collection (for example CustomersView) defined in the ViewModel as follows:
public
class
MyViewModel
{
private
readonly
QueryableEntityCollectionView<Customer> customersView;
private
readonly
NorthwindEntities objectContext;
public
MyViewModel()
{
this
.objectContext =
new
NorthwindEntities();
this
.customersView =
new
QueryableEntityCollectionView<Customer>(objectContext,
"Customers"
);
}
public
QueryableEntityCollectionView<Customer> CustomersView
{
get
{
return
this
.customersView; }
}
}
<
telerik:RadGridView
Name
=
"customersGrid"
...
ItemsSource
=
"{Binding CustomersView}"
/>
As to your second question, the CellValidating event is an UI event and you should not work with it in the ViewModel. You could instead implement the INotifyPropertyChanged interface (for notifications) and the IDataErrorInfo interface (for validation).
Regards,
Didie
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.

Hello Didie, thank you for your replay, but in my .xaml I have this:
<
telerik:RadEntityFrameworkDataSource
Name
=
"SuppliersEntityFrameworkDataSource"
QueryName
=
"Suppliers"
/>
<
telerik:RadGridView
ItemsSource
=
"{Binding DataView, ElementName=SuppliersEntityFrameworkDataSource}"
IsEnabled
=
"{Binding IsChecked, ElementName=UnLock, Mode=TwoWay}"
/>
<
telerik:RadDataPager
Source
=
"{Binding DataView, ElementName=SuppliersEntityFrameworkDataSource}"
PageSize
=
"17"
/>
In my code behind constructor I have this:
ObjectContext OC = (ObjectContext)MSSQLAccess.MSDataAccess.GetOBContext();
SuppliersEntityFrameworkDataSource.ObjectContext = OC;
But I want to have access to SuppliersEntityFrameworkDataSource in my VM.
That is the whole point.
You asked for an MVVM example. You can't place a visual control in a view model (code-behind).
That is why you should work with the QueryableEntityCollectionView<T> instead. Forget about the control. In fact the control RadEntityFrameworkDataSource is a very thin wrapper over this QueryableEntityCollectionView<T> class. All the work is actually done by QueryableEntityCollectionView<T>. That is why we made it public -- so you can place it in your view model and do MVVM.
So forget about the control. Please do as my colleague suggested. Expose this collection as a property on your view model and then bind both the grid and the pager directly to it.
Regards,
Ross
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.
Follow up: In case you do not need to perform any editing, i.e. your grid is read only.
You can simply expose ObjectContext.Suppliers as a property on your view model and then bind RadGridView and RadDataPager to it. Since ObjectContext.Suppliers is IQueryable RadGridView will be able to filter (Where), sort (OrderBy) and group (GroupBy) directly on the database server. RadDataPager will also do server-side paging (Skip and Take).
You can try this as well comletely eliminating the need for our control.
Kind regards,
Ross
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.

Hello Ross, thank’s for helping.
Did I unstained you right: the RadEntityFrameworkDataSource is not suitable for MVVM?
Regards Uwe
Yes, that is right, it is a visual control. You should use the suggested MVVM example.
Kind regards,Didie
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.

… ok, now I made the following:
In xaml:
<
telerik:RadGridView
Name
=
"MyGridView"
Margin
=
"29,89,38,70"
ItemsSource
=
"{Binding PagedSource, ElementName=Pager}"
>
<
i:Interaction.Triggers
>
<
i:InvokeCommandAction
Command
=
"{Binding SubmitChanges}"
/>
</
i:EventTrigger
>
<
i:EventTrigger
EventName
=
"RowLoaded"
>
<
i:InvokeCommandAction
Command
=
"{Binding RowLoaded}"
CommandParameter
=
"{Binding ElementName=MyGridView}"
/>
</
i:EventTrigger
>
</
i:Interaction.Triggers
>
</
telerik:RadGridView
>
<
telerik:RadDataPager
Name
=
"Pager"
Source
=
"{Binding Suppliers}"
PageSize
=
"17"
Grid.ColumnSpan
=
"2"
Margin
=
"29,0,38,42"
VerticalAlignment
=
"Bottom"
d:LayoutOverrides
=
"Height"
/>
In the ViewModel:
private
readonly
ObjectContext _oC = (ObjectContext)MSSQLAccess.MSDataAccess.GetOBContext();
public
ObjectContext OC
{
get
{
return
this
._oC; }
}
private
readonly
QueryableEntityCollectionView<MSSQLAccess.Supplier> _suppliers;
public
QueryableEntityCollectionView<MSSQLAccess.Supplier> Suppliers
{
get
{
return
this
._suppliers; }
}
/// <summary>
/// Constructor
/// </summary>
public
CurrentDataViewModel()
{
_oC =
new
MSSQLAccess.APOSEntities(MSSQLAccess.MSDataAccess.EntityBuilder.ToString());
_suppliers =
new
QueryableEntityCollectionView<MSSQLAccess.Supplier>(_oC,
"Suppliers"
);
}
...
/// <summary>
/// SubmitChanges Command Function
/// </summary>
public
void
SubmitChangesCF()
{
OC.SaveChanges();
}
The data will be displayed, I can edit it in the RadGridView and they are stored back into the DB (via the SubmitChangesCF function). Everything works fine so far.
But I see the hole table (Suppliers) in the GridView, is it possible to fill the GridView with a select statement, something like:
IQueryable<MSSQLAccess.Supplier IQsu;
IQsu = ((MSSQLAccess.APOSEntities)OC).Suppliers.Where(o => o.ShippingWeight == 10);
List<MSSQLAccess.Supplier> Su = IQsu.ToList<MSSQLAccess.Supplier>();
Please can you give me a hint
a) if this is possible and how to do it
b) reload the data (from the program) into the GridView, for example if the data has changed in the meantime in the DB
Or is there a complete better way to do what I want?
Kind Regarts

I found it out by myself:
((QueryableEntityCollectionView<MSSQLAccess.Supplier>)Suppliers).Refresh();

setting a filter seems to be a possibility:
DateTime ToDay = DateTime.Now.Date;
GridViewColumn IdColumn = _theGridView.Columns[
"InsertDate"
];
IColumnFilterDescriptor idFilter = IdColumn.ColumnFilterDescriptor;
idFilter.SuspendNotifications();
idFilter.FieldFilter.Filter1.Operator = Telerik.Windows.Data.FilterOperator.IsGreaterThanOrEqualTo;
idFilter.FieldFilter.Filter1.Value = ToDay;
idFilter.ResumeNotifications();
Filtering, sorting, grouping or manually calling Refresh will all refresh the current view.
Here you can learn all about filtering. You can "simulate" everything an end-user can do through the UI by using IColumnFilterDescriptors. If you do not care about the UI, you can directly add FilterDescriptos to the QECV<T>.
All the best,
Ross
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.