ローカル DBSet を使用してクエリを実行しようとしていますが、思いついた 2 つの解決策に問題があります。
解決策 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: これにより、クエリが実行され、データが正しくバインドされます。また、データはすべての新しいクエリに対して更新されますが、データグリッド内のデータは編集できなくなります
//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);
複数のクエリを実行してデータを編集できるソリューションを誰かが持っていますか?