1

我使用以下两个命令在 C#/winform 中使用 DBLinq 创建了一个 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)
...

数据库文件存在,我有表。任何想法?

4

0 回答 0