Included EntityCollection

4 posts, 1 answers
  1. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 16 Jun 2011 Link to this post

    I am using the RADDomainDataSource to expose my data model via a ViewModel to my View.

    Here is a sample of my code i have build with the help from this forum and samples provided by telerik.

    RabbitDomainContext _context = new RabbitDomainContext();
      
            public ICommand SaveChangesCommand { get; set; }
      
            public ClientsViewModel()
            {
                if (!DesignerProperties.IsInDesignTool)
                {
                    EntityQuery<Organisation> getOrganisationQuery = _context.GetOrganisationsQuery();
                    _organisations = new QueryableDomainServiceCollectionView<Organisation>(_context, getOrganisationQuery);
                    _organisations.PageSize = 25;
                    _organisations.AutoLoad = true;
      
                    SaveChangesCommand = new DelegateCommand(SaveChanges, CanSaveChanges);
                }
            }
      
            private QueryableDomainServiceCollectionView<Organisation> _organisations;
              
            public IEnumerable Organisations
            {
                get { return _organisations; }
            }
      
            private Organisation _selectedOrganisation;
      
            public Organisation SelectedOrganisation
            {
                get { return _selectedOrganisation; }
                set
                {
                    if (value != _selectedOrganisation)
                    {
                        _selectedOrganisation = value;
                        OnPropertyChanged("SelectedOrganisation");
                    }
                }
            }
      
            private bool CanSaveChanges(object param)      
            {           
                return true;  
            }
      
            private void SaveChanges(object param)
            {
                _organisations.SubmitChanges();
            }


    It works very well. I bind the data to a Grid as Well as a DataForm.

    Inside my Organistions class i have a collections of Offices like this:

    Organisations.Offices.

    I can bind to a new Grid like so:
    ItemsSource="{Binding SelectedOrganisation.Offices}"

    Which also works. However i wanted to bind a dataform to one specific Office.

    Previously when i did not use MVV and none of the telerik controls, i did something like that by creating a filter like this:

    And using it in the XAML.
    private void PhoneViewSource_Filter(object sender, System.Windows.Data.FilterEventArgs e)
            {
                if (((CommsMethod)e.Item).Z_Position == 0 && ((CommsMethod)e.Item).Owner_Type == 0)
                    e.Accepted = true;
                else
                    e.Accepted = false;
      
            }

    I see that the DomainDatSource has filters, is that something i could use in this case, and how would i do that, considering my DomainDataSource is in my ViewModel.

    Thanks
  2. Answer
    Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 20 Jun 2011 Link to this post

    Hello Andrew,

    First of all let's make sure that we are talking about the same things here.

    You are constantly referring to the RadDomainDataSource control while it is totally clear that you are in fact using its inner view called QueryableDomainServiceCollectionView<T> which is the correct approach when doing MVVM. RadDomainDataSource is a control and is defined in XAML. On the other hand, the QDSCV<T> is a collection view which is supposed to be used by view models like described in my blog post. The QDSCV is not an UIElement and can be used by a view model.

    As far as I understand each time you mention RDDS you actually mean QDSCV? Is that correct? There is a clear distinction between both. In case you have not read my blog post, please do it now.

    Now, there are two ways to filter the entities that arrive on the client. One of the is to add a FilterDescriptor to the FilterDescriptors collection. This FilterDescriptor will be transformed to a Where clause on the EntityQuery and sent to the server. This is demonstrated in this demo.

    The second way would be to use QueryParameters like this demo does.

    I hope this helps.

    Regards,
    Ross
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Andrew
    Andrew avatar
    171 posts
    Member since:
    Jun 2009

    Posted 20 Jun 2011 Link to this post

    I do indeed mean QueryableDomainServiceCollectionView
    I had a look at the blog as well as the demos you mention.
    Neither of them is relevant to my specific question.
    I have in the meantime come up with a way to (sort of) do what i need.
    I have extended the ViewModel to include a new property PrimaryOffice and i set it using a Linq query.

    I was reluctant to do that as i tried to stick leave as much of my old code as possible.

    However as you rightly point out QDSCV is very different to the RadDomainDataSource control, and i need to adjust my code accordingly.

    I have encountered some issues with binding this new property to my DataForm, but that is an issue for a different forum, and i have already posted a question on there.

    Thank you for your help.

  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 20 Jun 2011 Link to this post

    Hi Andrew,

    In fact RadDomainDataSource is almost empty. When you use RadDomainDataSource it will automatically create one of those QDSCV-s internally and start delegating all of the work to it. The only thing that RadDomainDataSource adds is the fact that it is an UIElement which allows binding in XAML and the LoadDelay functionality. Almost all of the actual job is being done by the QDSCV.

    Best wishes,
    Ross
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top