次の 2 つのコマンドを使用して、DBLinq を使用して C#/winform で Linq および SQLite アプリを作成しました。
DbMetal /provider:Sqlite /conn "Data Source=path\to\database.s3db" /dbml:path\to\Database.dbml
と:
DbMetal /code:path\to\DatabaseContext.cs path\to\Database.dbml
データベースへの接続を取得するには:
string dataSource = @"Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "database.s3db";
var connection = new SQLiteConnection(dataSource);
Main db = new Main(connection, new SqliteVendor());
データベースにクエリを実行するには:
var user = db.User.SingleOrDefault(u => u.UserName == username);
このコード行を実行すると、No shuch table
例外が発生します。
no such table: main.USER
System.Data.SQLite.SQLiteException was unhandled HResult=-2147467259 Message=SQLite error
no such table: main.USER
Source=System.Data.SQLite
ErrorCode=-2147467259
StackTrace:
at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at DbLinq.Data.Linq.Sugar.Implementation.QueryRunner.Select[T](SelectQuery selectQuery)
at DbLinq.Data.Linq.Sugar.Implementation.QueryRunner.SelectSingle[S](SelectQuery selectQuery, Boolean allowDefault)
at DbLinq.Data.Linq.Sugar.Implementation.QueryRunner.SelectScalar[S](SelectQuery selectQuery)
at DbLinq.Data.Linq.Implementation.QueryProvider`1.Execute[TResult](Expression expression)
at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
...
データベースファイルが存在し、テーブルがあります。何か案が?