Note that there are some explanatory texts on larger screens.

plurals
  1. POAssociation property in DomainCollectionView and WCF RIA Services
    text
    copied!<p>I have a association in my poco class, ex:</p> <pre><code>public class Category() { [Key] public int id { get; set} public string Name { get; set; } /* HERE */ public virtual ICollection&lt;Book&gt; Books {get; set;} } public class Book() { [Key] public int id { get; set} public string Name { get; set; } } </code></pre> <p>I use MVVM patern, MVVM Light and RIA Services Toolkit. My Domain Service implementation contains a method GetCategories that include their books, ex:</p> <pre><code>public IQueriable&lt;Category&gt; GetCategories() { return Model.Categories.Include("Books").OrderBy(pCategory =&gt; pCategory.Name); } </code></pre> <p>In my ViewModel I have a DomainCollectionView that load GetGruposQuery. I also have a property for bind a grid and other controls, like:</p> <pre><code>public ICollectionView CollectionViewCategories { get { return myDomainCollectionViewCategories;} } </code></pre> <p>I need get a child property CollectionView.Books for bind my controls and ADD, REMOVE itens in view, but this property is only EntityCollection and isn't a DomainCollectionView that contains methods for ADD, REMOVE, etc.</p> <p>How I can get the current Books property (of CollectionViewCategories) as DomainCollectionView in my ViewModel?</p> <p>Thank you!</p> <hr> <p>I solve this question with: (CollectionViewCategories.CurrentItem as Category).Books.Remove(CollectionViewBooks.CurrentItem as Book)</p> <pre><code>private ICollectionView CreateView(Object source) { CollectionViewSource cvs = new CollectionViewSource(); cvs.Source = source; return cvs.View; } //... //After CollectionViewCategories loaded: CollectionViewCategories.CurrentChanged += (s, e) =&gt; { if (CollectionViewCategories.CurrentItem != null) { CollectionViewBooks = CreateView(fContext.Categories.Where(p =&gt; p.Id == (CollectionViewCategories.CurrentItem as Category).Id).FirstOrDefault().Books); } else { CollectionViewBooks = null; } RaisePropertyChanged("CollectionViewBooks"); }; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload