0
我正在嘗試使用本地DBSet運行查詢,但遇到了我提出的兩個解決方案的問題。使用DBSet本地進行多個查詢
解決方案1:這將運行查詢並將查詢結果綁定到我的結果控件,並且數據可以被編輯並保存到數據庫。但是,如果我嘗試在同一個表上運行另一個查詢(如果我切換表一切正常),結果項不會更新(它將添加任何新結果,但任何舊結果應該不再存在)
//This part gets a DBSet from the context with the passed in table
Type t = context.GetType();
dynamic myDBSet= t.InvokeMember(table,
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.GetProperty, null, context, new object[0]);
//This is the query I want to run. I am then loading it into the localDBSet
((IQueryable)myDBSet).AsQueryable().Where(condition).Load();
results.ItemsSource = myDBSet.Local;
解決方案2:這將運行查詢並正確綁定數據。另外,數據將更新所有新的查詢,但在DataGrid中的數據不再是可編輯
//This part gets a DBSet from the context with the passed in table
Type t = context.GetType();
dynamic myDBSet= t.InvokeMember(table,
BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.GetProperty, null, context, new object[0]);
//This is the query I want to run. I am then loading it into the localDBSet
((IQueryable)myDBSet).AsQueryable().Where(condition).Load();
DbSet copiedDBSet= myDBSet;
results.ItemsSource = copiedDBSet.Local.AsQueryable().Where(condition);
有沒有人有一個解決方案,可以讓我運行多個查詢,仍然編輯數據?