title: how to make Collectionviewsource with entityframework and observablecollection type independent
body: <p>I've got a couple of pieces of code that I would love to make type independent.</p>
  
  <p>context:
  I've got an edmx file generated from a couple (8) of tables from a mssql database.
  Using linq on these entity's I want to get a observable collection that I can use as a source for a CollectionViewSource, which in turn is bound to a datagrid. apply some filterting etc..</p>
  
  <p>the problem:
  The problem i'm getting is when i want the code for the binding/filtering/adding rows/removing rows to be independent of which table i generate my collection from. As of now I can only find a workable solution if I use switchcases in a number of places in my code. And I would rather not in favor of reuse-ability.</p>
  
  <p>the question:
  What do I do, what do i need to change, what do I mis. in short how do I get rid of the switchcases?</p>
  
  <p>code snippit:</p>
  
  <pre><code>        ent = new Access2SQLEntitiesCon();
          CVS = (CollectionViewSource)this.Resources["CVS"];
          ///don't want this \/
          switch (tbl_enum)
          {
              case 1:
                      var wnings = from woning in ent.tblWoning
                               where woning.volg == ProjNum
                               select woning;
                  var _oc  =  new ObservableCollection&lt;tblWoning&gt;(wnings);
                  _oc.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(OC_CollectionChanged);
                  CVS.Source = _oc;
                      break;
          }
          //don't want that /\ 
  
  
          CVS.Filter += CVS_Filter;
          MakeFilterListEFM();
  </code></pre>
  
  <p>so, I can post the other two problem-area's but I think this will do for now. I Get that I can change the linq part to something more dynamic but that not where the issue is. Its the observable collection and its mandatory type... :(</p>
  
  <p><strong>edit:cont:</strong>
  I try'd using a ObservableCollection<code>&lt;object</code>> but then my DataGrid just displays a bunch of small horizontal lines. Because it doesn't know anymore what type of items it has to display. Is there maybe a way to have that in another variable en point that (via datatemplate?) to the datagrid in order for the autogenerated columns to work again.</p>
  
  <p><strong>edit 2:</strong>
  In short. What do I need to Do to replace ObservableConnection<code>&lt;tblWoning</code>> with ObservableConnection<code>&lt;object</code>> or ObservableConnection<code>&lt;dynamic</code>>. But keeping the ability to autogenerate columns in the datagrid. </p>