2016-03-07 36 views
0

我們有存儲在SQLite數據庫中的數據。數據顯示在DevExpress.XtraGrid.GridControl中。要獲得相關數據,我們創建臨時表並填寫它。 數據上下文:刷新System.Data.Entity.DbContext中的數據

public class AccountsSQLiteDataContext : DbContext 
{ 
    public AccountsSQLiteDataContext(IDbConnection connection) 
     : base((SQLiteConnection)connection, false) 
    { 
     Database.SetInitializer<AccountsSQLiteDataContext>(null); 
    } 

    public DbSet<tmp_acc> TmpAccounts { get; set; } 

    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
     modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); 
    } 
} 

工作,的DbContext:

AccountsSQLiteDataContext myContext = new AccountsSQLiteDataContext(myDbConnection); 

public IQueryable AccountTable 
{ 
    get 
    { 
     return myContext.TmpAccounts; 
    } 
} 

DevExpress.Data.Linq.LinqServerModeSource myLinqSource = = new DevExpress.Data.Linq.LinqServerModeSource(); 
myLinqSource.QueryableSource = AccountTable; 
myGridControl.DataSource = myLinqSource; 

和數據變化後,我打電話:myLinqSource.Reload();

而不是在SQLite的臨時表中的數據的所有更改網格顯示。添加和刪​​除表格行會生效。但單元格文本中的更改未顯示。 過濾器函數會以新值生效。見printscreen。在過濾器選項中是正確的值,在網格中是舊值。

如何刷新存儲在DbContext中的本地數據,以便在臨時表中更改後顯示正確的值?

+0

您是否使用WinForms DataGridView? –

+0

我們使用DevExpress UI框架及其DevExpress.XtraGrid.GridControl和DevExpress.XtraGrid.Views.Grid.GridView。 –

回答

0

我發現了兩個解決方案。他們都將取消項目的高速緩存中的EF數據模型:在SQL表

  1. 使用自動增量字段,表中的任何數據變化
  2. 使用AsNoTracking擴展方法從數據庫實體裝載後重建:

    公衆的IQueryable AccountTable { 得到 { 回報myContext.TmpAccounts.AsNoTracking(); } }