@@ -43,7 +43,6 @@ public class Stock
43
43
{
44
44
[PrimaryKey , AutoIncrement ]
45
45
public int Id { get ; set ; }
46
- [MaxLength (8 )]
47
46
public string Symbol { get ; set ; }
48
47
}
49
48
@@ -69,7 +68,10 @@ Both APIs are explained in the two sections below.
69
68
Once you have defined your entity, you can automatically generate tables in your database by calling ` CreateTable ` :
70
69
71
70
``` csharp
72
- var db = new SQLiteConnection (" foofoo" );
71
+ // Get an absolute path to the database file
72
+ var databasePath = Path .Combine (Environment .GetFolderPath (Environment .SpecialFolder .MyDocuments ), " MyData.db" );
73
+
74
+ var db = new SQLiteConnection (databasePath );
73
75
db .CreateTable <Stock >();
74
76
db .CreateTable <Valuation >();
75
77
```
@@ -90,7 +92,7 @@ Similar methods exist for `Update` and `Delete`.
90
92
The most straightforward way to query for data is using the ` Table ` method. This can take predicates for constraining via WHERE clauses and/or adding ORDER BY clauses:
91
93
92
94
``` csharp
93
- var conn = new SQLiteConnection (" foofoo " );
95
+ var conn = new SQLiteConnection (databasePath );
94
96
var query = conn .Table <Stock >().Where (v => v .Symbol .StartsWith (" A" ));
95
97
96
98
foreach (var stock in query )
@@ -129,7 +131,10 @@ will work for you.
129
131
Once you have defined your entity, you can automatically generate tables by calling ` CreateTableAsync ` :
130
132
131
133
``` csharp
132
- var conn = new SQLiteAsyncConnection (" foofoo" );
134
+ // Get an absolute path to the database file
135
+ var databasePath = Path .Combine (Environment .GetFolderPath (Environment .SpecialFolder .MyDocuments ), " MyData.db" );
136
+
137
+ var conn = new SQLiteAsyncConnection (databasePath );
133
138
134
139
await conn .CreateTableAsync <Stock >();
135
140
@@ -144,7 +149,7 @@ Stock stock = new Stock()
144
149
Symbol = " AAPL"
145
150
};
146
151
147
- var conn = new SQLiteAsyncConnection (" foofoo " );
152
+ var conn = new SQLiteAsyncConnection (databasePath );
148
153
149
154
await conn .InsertAsync (stock );
150
155
@@ -158,7 +163,7 @@ you can add predictates for constraining via WHERE clauses and/or adding ORDER B
158
163
retrieval methods - ` ToListAsync ` , ` FirstAsync ` , or ` FirstOrDefaultAsync ` - is called.
159
164
160
165
``` csharp
161
- var conn = new SQLiteAsyncConnection (" foofoo " );
166
+ var conn = new SQLiteAsyncConnection (databasePath );
162
167
var query = await conn .Table <Stock >().Where (v => v .Symbol .StartsWith (" A" ));
163
168
164
169
var result = await query .ToListAsync ();
@@ -173,7 +178,7 @@ operations provided by `InsertAsync` etc you can issue `ExecuteAsync` methods to
173
178
Another helpful method is ` ExecuteScalarAsync ` . This allows you to return a scalar value from the database easily:
174
179
175
180
``` csharp
176
- var conn = new SQLiteAsyncConnection (" foofoo " );
181
+ var conn = new SQLiteAsyncConnection (databasePath );
177
182
178
183
var result = await conn .ExecuteScalarAsync <int >(" select count(*) from Stock" );
179
184
0 commit comments