DataGrid (XCeed DataGrid)에 항목을 표시하는 WPF 응용 프로그램이 있습니다. 이 응용 프로그램은 데이터베이스 (SQLite)에 많은 항목이 포함되어있는 경우로드하는 데 시간이 걸리므로 필요에 따라로드 할 수 있도록 yield return을 사용하고 싶습니다. 나는 XCeed DataGrid supports UI virtualization을 알고 있지만, 동기 코드의 다음 블록을 어떻게 변환 할지는 모르겠습니다.데이터 레이어에서 수익률 반환
현재 UI 저하를 막기 위해 BackgroundWorker에로드 된 목록입니다. 그리드의 DataSource로 채워집니다.
public override IList<IRecipe> GetRecipes()
{
List<IRecipe> recipes = new List<IRecipe>();
Execute(conn =>
{
using (var cmd = conn.CreateCommand()) {
cmd.CommandText = "SELECT * FROM recipes ORDER BY Name";
var reader = cmd.ExecuteReader();
while (reader.Read()) {
try {
var recipe = GetRecipe(reader);
recipes.Add(recipe);
} catch (Exception ex) {
Console.WriteLine(string.Format("Error loading recipe: {0}", ex.Message));
}
}
reader.Close();
cmd.CommandText = "SELECT * FROM Ingredients WHERE Recipe = @Recipe";
cmd.Parameters.AddWithValue("@Recipe", string.Empty);
foreach (IRecipe recipe in recipes) {
cmd.Parameters["@Recipe"].Value = recipe.ID;
reader = cmd.ExecuteReader();
while (reader.Read()) {
try {
IIngredient Ingredient = GetIngredient(reader);
recipe.Ingredients.Add(Ingredient);
} catch (Exception ex) {
Console.WriteLine(string.Format("Error adding Ingredient to recipe '{0}': {1}", recipe.Name, ex.Message));
}
}
reader.Close();
}
}
또는 내가 속도를 개선하고 게으른 로딩을 사용할 수있는 다른 방법은 무엇입니까?
직접 모든 것을로드해야합니까? – jgauffin