xxxxxxxxxx
1
using System.Data.SQLite;
2
using ServiceStack.OrmLite;
3
4
5
OrmLiteUtils.PrintSql();
6
7
8
var dbFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);
9
using var db = dbFactory.Open();
10
db.CreateTableIfNotExists<MyType>();
11
12
13
db.Save(new MyType { field1 = "Hello", field2 = "World!" });
14
15
16
try // first -- like I'd expect it to work:
17
{
18
var q = db.From<MyType>().Where("field1 = @theVariable", new { theVariable = "Hello" });
19
var results = db.Select(q);
20
}
21
catch (SQLiteException ex) { Console.WriteLine(ex.Message); }
22
23
try // same problem if I convert to SQL statement and run as string....
24
{
25
var q2 = db.From<MyType>().Where("field1 = @theVariable", new { theVariable = "Hello" });
26
var stmt = q2.ToSelectStatement();
27
var results2 = db.Select<MyType>(stmt);
28
}
29
catch (SQLiteException ex) { Console.WriteLine(ex.Message); }
30
31
32
try // ... but it works if the variable is inserted at the end
33
{
34
var q2 = db.From<MyType>().Where("field1 = @theVariable");
35
var stmt = q2.ToSelectStatement();
36
var results2 = db.Select<MyType>(stmt, new { theVariable = "Hello" });
37
}
38
catch (SQLiteException ex) { Console.WriteLine(ex.Message); }
39
40
// db.SelectMany doesn't have the option of passing in an SQL-string + parameters
41
run