2013-03-25 45 views
0

好吧,我想我現在已經掌握了大部分知識,但是很遺憾我找不到任何可以acutal幫助我的教程,因爲大多數教程都是使用SQL Connections和即時通訊使用實體框架。 到目前爲止,我創建了一個名爲Farve的CSLA Business類和一個名爲FarbeListe的CSLA Business List類。在我的xaml中,我有一個網格視圖,其中列出了模型。但我現在不知道如何獲取數據,但我很確定我很接近。請幫助我一個簡單的例子,不要發佈任何教程,我認爲我現在最瞭解他們,他們仍然沒有幫助。數據庫Accsess WPF MVVM的最後一步

這裏我的里昂證券類FARBE

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Csla; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows; 
using MusterConnectionDB.Datenbank; 

namespace MusterConnectionDB.Business 
{ 
    [Serializable] 
    public class Farbe : Csla.BusinessBase<Farbe> 
    { 

     TestDBEntities db = new TestDBEntities(); 

     public Farbe() 
     { 
      BusinessRules.AddRule(new Csla.Rules.CommonRules.Required(FarbauswahlNrProperty)); 
      BusinessRules.AddRule(new Csla.Rules.CommonRules.MinValue<int>(FarbauswahlNrProperty, 3)); 


     } 

     #region Properties 

     public static readonly PropertyInfo<int> FarbauswahlNrProperty = RegisterProperty<int>(c => c.FarbauswahlNr); 
     public int FarbauswahlNr 
     { 
      get { return GetProperty(FarbauswahlNrProperty); } 
      set 
      { 

       SetProperty(FarbauswahlNrProperty, value); 
      } 
     } 


     public static readonly PropertyInfo<string> KurztextProperty = RegisterProperty<string>(c => c.Kurztext); 
     public string Kurztext 
     { 
      get { return GetProperty(KurztextProperty); } 
      set { SetProperty(KurztextProperty, value); } 
     } 

     public static readonly PropertyInfo<string> RessourceProperty = RegisterProperty<string>(c => c.Ressource); 
     public string Ressource 
     { 
      get { return GetProperty(RessourceProperty); } 
      set { SetProperty(RessourceProperty, value); } 
     } 

     public static readonly PropertyInfo<bool> Vari1Property = RegisterProperty<bool>(c => c.Vari1); 
     public bool Vari1 
     { 
      get { return GetProperty(Vari1Property); } 
      set { SetProperty(Vari1Property, value); } 
     } 

     public static readonly PropertyInfo<string> Vari2Property = RegisterProperty<string>(c => c.Vari2); 
     public string Vari2 
     { 
      get { return GetProperty(Vari2Property); } 
      set { SetProperty(Vari2Property, value); } 
     } 

     #endregion 

     #region Synchronous Factory Methods 

     public class DataEventArgs : EventArgs 
     { 
      public DataEventArgs(Farbe data) 
      { 
       this.Data = data; 
      } 

      public Farbe Data { get; set; } 
     } 

     internal static Farbe New() 
     { 
      return DataPortal.CreateChild<Farbe>(); 
     } 


     internal static Farbe Get(Farbe data) 
     { 
      if (data == null) 
       return null; 

      return DataPortal.FetchChild<Farbe>(data); 
     } 


     #endregion 

     #region DataProtal Methods 




     private void Child_Update() 
     { 
      using (var ctx = Csla.Data.ObjectContextManager<TestDBEntities>.GetManager(EntitiesDatabase.Name)) 
      { 
       var data = ctx.ObjectContext.Farben.SingleOrDefault(e => e.FarbauswahlNr == this.FarbauswahlNr); 

       data.Kurztext = ReadProperty<string>(KurztextProperty); 
       data.Ressource = ReadProperty<string>(RessourceProperty); 
       data.Var1 = ReadProperty<bool>(Vari1Property); 
       data.Vari2 = ReadProperty<string>(Vari2Property); 
       ctx.ObjectContext.SaveChanges(); 

      } 
     } 

     private void Child_Insert() 
     { 
      using (var ctx = Csla.Data.ObjectContextManager<TestDBEntities>.GetManager(EntitiesDatabase.Name)) 
      { 

       try 
       { 
        var data = new Datenbank.Farbe(); 
        data.Kurztext = ReadProperty<string>(KurztextProperty); 
        data.Ressource = ReadProperty<string>(RessourceProperty); 
        data.Var1 = ReadProperty<bool>(Vari1Property); 
        data.Vari2 = ReadProperty<string>(Vari2Property); 
        ctx.ObjectContext.Farben.AddObject(data); 
        ctx.ObjectContext.SaveChanges(); 
       } 
       catch (Exception e) 
       { 

        MessageBox.Show(e.ToString()); 
       } 


      } 
     } 

     private void Child_Delete() 
     { 

      using (var ctx = Csla.Data.ObjectContextManager<TestDBEntities>.GetManager(EntitiesDatabase.Name)) 
      { 
       try 
       { 
        var data = ctx.ObjectContext.Farben.SingleOrDefault(e => e.FarbauswahlNr == this.FarbauswahlNr); 
        ctx.ObjectContext.Farben.DeleteObject(data); 
        ctx.ObjectContext.SaveChanges(); 
       } 
       catch (Exception e) 
       { 
        MessageBox.Show(e.ToString()); 

       } 
      } 
     } 



     #endregion 

    } 
} 

現在我的里昂證券名單克拉斯FarbeListe

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Csla; 
using MusterConnectionDB.Business; 

namespace MusterConnectionDB.Business 
{ 
    public class FarbeListe : Csla.BusinessListBase<FarbeListe, Farbe> 
    { 
     public FarbeListe() 
     { 

     } 


     protected override void Child_Create() 
     { 
      base.Child_Create(); 
     } 

     private void Child_Fetch(IEnumerable<Farbe> data) 
     { 

      RaiseListChangedEvents = false; 

      foreach (var item in data) 
      { 
       this.Add(Farbe.Get(item)); 

      } 

      RaiseListChangedEvents = true; 
     } 

     internal static FarbeListe Get(IEnumerable<Farbe> data) 
     { 
      if (data == null) 
       return null; 

      return DataPortal.FetchChild<FarbeListe>(data); 
     } 

     internal static FarbeListe New() 
     { 
      return DataPortal.CreateChild<FarbeListe>(); 
     } 

     internal static FarbeListe GetAll() 
     { 

      return DataPortal.Fetch<FarbeListe>(); 
     } 
    } 

} 

現在把我們的代碼請成方法至極是模型類FarbeViewModel。我只需要獲取屬性模型的數據。

public void ExecuteAktu(object obj) 
{ 




} 
+0

@WiiMaxx嗯,我想,這是由於他正在使用的CSLA。但我不確定。哦,請用英文寫。這對非德語用戶是不公平的。 ; o) – DHN 2013-03-25 07:51:16

+0

@DHN我剛剛用他的nativ語言回答了他的問題:o)並且他說_put我們的代碼請進入那個方法,這是模型類FarbeViewModel_這對我意味着他有一個單獨的模型 – WiiMaxx 2013-03-25 07:54:27

+0

@WiiMaxx好吧,因爲我們不是'一個人'在這裏,這仍然是不公平的,因爲沒有人能夠參與討論。 ; o) – DHN 2013-03-25 07:56:42

回答

0

此行FarbeViewModel

Model = MusterConnectionDB.Business.FarbeListe.GetAll(); 

的構造函數,這在FarbListe CSLA的businessList類

private void DataPortal_Fetch() 
    { 
     using (var ctx = Csla.Data.ObjectContextManager<Datenbank.TestDBEntities>.GetManager(EntitiesDatabase.Name)) 
      ReadData(ctx.ObjectContext.Farben); 
    } 

    private void ReadData(IEnumerable<Datenbank.Farbe> data) 
    { 
     // Partial Method BeforeReadData 


     RaiseListChangedEvents = false; 

     foreach (var item in data) 
      this.Add(Farbe.Get(item)); 
     RaiseListChangedEvents = true; 


    } 

和finaly這在商務艙FARBE

internal static Farbe Get(Datenbank.Farbe data) 
    { 
     try 
     { 
      if (data == null) 
       return null; 

      return DataPortal.FetchChild<Farbe>(data); 
     } 
     catch (System.Exception e) 
     { 
      MessageBox.Show(e.ToString()); 
     } 
     return null; 

    } 

    private void Child_Fetch(Datenbank.Farbe data) 
    { 

     LoadProperty(FarbauswahlNrProperty, data.FarbauswahlNr); 
     LoadProperty(KurztextProperty, data.Kurztext); 
     LoadProperty(RessourceProperty, data.Ressource); 
     LoadProperty(Vari1Property, data.Var1); 
     LoadProperty(Vari2Property, data.Vari2); 

    } 

這就是我如何從我的數據庫中讀取數據.... -.-' 簡單的權利? :D