1
我該如何使這個方法通用來保存重複的代碼?C#泛型SQLite其中查詢Methode
private async Task<int> CheckCategorieDescription(string description)
{
try
{
var db = new SQLiteAsyncConnection(pathToDatabase);
var query = db.Table<Categorie>().Where(v => v.Description.Contains(description));
var list = await query.ToListAsync();
return list.Count;
}
catch (SQLiteException ex)
{
return -1;
}
}
這將是偉大的CodeGo.net,當將代碼將看起來像。
private async Task<int> CheckDescription<T>(string description)
{
try
{
var db = new SQLiteAsyncConnection(pathToDatabase);
var query = db.Table<T>().Where(v => v.Description.Contains(description));
var list = await query.ToListAsync();
return list.Count;
}
catch (SQLiteException ex)
{
return -1;
}
}
有沒有一種方法在「db.Table」這個Position中插入T的類型。
感謝您的幫助