Saturday, September 6, 2014

Some overview of Entity Framework implementation

  1.         private agsEntities agsEntities = new agsEntities(connectionstring);
  2.  
  3.         public ObservableCollection<FAMILY> FamilyCollection.....
  4.         ..........INotify
  5.  
  6.  
  7.         public ObjectQuery<FAMILY> FamiliesQuery;
  8. // FAMILY class is defined as:      public partial class FAMILY : EntityObject
  9. // mostly this was autocreated by EF
  10.         public ObjectQuery<FAMILY> GetFAMILIESQuery(agsEntities agsEntities)
  11.         {
  12.             ObjectQuery<FAMILY> fAMILIESQuery = agsEntities.FAMILIES;
  13.             return fAMILIESQuery;
  14.         }
  15.  
  16.         private CollectionViewSource _familiesViewSource;
  17.         public CollectionViewSource FamiliesViewSource
  18.         {
  19.             get
  20.             {
  21.                 if (_familiesViewSource == null)
  22.                     GetFamilyViewSource();
  23.                 return _familiesViewSource;
  24.             }
  25.         }
  26.  
  27.         private void GetFamilyViewSource()
  28.         {
  29.             // Load data into FAMILIES
  30. //this is ObjectQuery<T>
  31.             this.FamiliesQuery = this.GetFAMILIESQuery(this.agsEntities);
  32. //this is a CollectionViewSource......
  33.             this._familiesViewSource = new CollectionViewSource();
  34. //this is an ObjectResult<T>
  35.             this._familiesViewSource.Source = this.FamiliesQuery.Execute(MergeOption.AppendOnly);
  36. //refresh the view (in this case a DataGrid is bound to FamiliesViewSource
  37.             this._familiesViewSource.View.Refresh();
  38. //and into an observable collection just in case
  39. //agsEntities.FAMILIES is defined by EF as:       public ObjectSet<FAMILY> FAMILIES
  40.             foreach (FAMILY thing in agsEntities.FAMILIES)
  41.                 FamilyCollection.Add(thing);
  42.  
  43.         }

No comments:

Post a Comment