praeclarum / sqlite-net

Simple, powerful, cross-platform SQLite client and ORM for .NET
MIT License
4.07k stars 1.42k forks source link

'AsyncTableQuery<obj>' does not contain a definition for 'GetAwaiter' #639

Open Whrothus opened 7 years ago

Whrothus commented 7 years ago

In Xamarin Shared VS2015 sqlite-net-pcl 1.4.118

I try this code public async Task<List > GetAlComplete() { query = await _connection.Table().Where(v => v._naam.StartsWith("A"));
return await query.ToListAsync(); } get this error Severity Code Description Project File Line Suppression State Error CS1061 'AsyncTableQuery' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'AsyncTableQuery' could be found (are you missing a using directive or an assembly reference?)

I try this var query = await _connection.Table().ToListAsync(); return query; No problem it runs normal (i get the full list)

Some background code private SQLiteAsyncConnection _connection; _connection = Xamarin.Forms.DependencyService.Get().GetConnection(); public interface ISQLiteDb { SQLiteAsyncConnection GetConnection(); } [assembly: Dependency(typeof(SQLiteDb))] namespace MyProject.Droid.DataBase { class SQLiteDb : ISQLiteDb { public SQLiteAsyncConnection GetConnection() { var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var path = Path.Combine(documentsPath, "MySQLite.db3"); return new SQLiteAsyncConnection(path); } } } class CheckList : IDataBaseObject { [Ignore] static public MainBussines _mainBuss { get; set; } [PrimaryKey , AutoIncrement] public int ID { get; set; } [MaxLength(255)] public string _naam { get; set; } }

schuettecarsten commented 7 years ago

You need to remove the "await" from the first line in your method. There is no async operation in this line, so you cannot await it. The second line is Async (ToListAsync), so you need to await it. So, it's not a SQLite issue.

public async Task<List > GetAlComplete()
{
query = _connection.Table().Where(v => v._naam.StartsWith("A"));
return await query.ToListAsync();
}
ikbenben commented 6 years ago

@praeclarum I came across this issue today too because the sample code in the README indicates you need the await keyword. Can the README be updated to read correctly. cheers