Created
December 15, 2012 23:04
-
-
Save npatta01/4300253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Globalization; | |
using System.Linq; | |
using System.Net.Mime; | |
using System.Text; | |
using System.Threading.Tasks; | |
using SQLite; | |
namespace SqlLiteTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//function to test possible problem | |
testMethod().GetAwaiter().GetResult(); | |
Console.ReadLine(); | |
} | |
private static async Task testMethod() | |
{ | |
//create an image | |
Image i = new Image() | |
{ | |
ID = 5, | |
ImageName = "testImage" | |
}; | |
string ImageName = "testImage"; | |
int ID; | |
//open database and drop and create and exsiting image table | |
SQLiteAsyncConnection CurrentConnection = new SQLiteAsyncConnection("DB"); | |
await CurrentConnection.DropTableAsync<Image>(); | |
await CurrentConnection.CreateTableAsync<Image>(); | |
//insert image; should have id 1 | |
ID = await CurrentConnection.InsertAsync(i); | |
Debug.Assert(ID == 1); | |
List<Image> result; | |
//retirve entry by imagename | |
if (ImageName != null) | |
{ | |
var query = CurrentConnection.Table<Image>().Where(d => d.ImageName == ImageName); | |
result = query.ToListAsync().GetAwaiter().GetResult(); | |
Debug.Assert(result.Count==1); | |
} | |
//retrieve image by ID | |
if (ID != null && ID > 0) | |
{ | |
var query = CurrentConnection.Table<Image>().Where(g => g.ID == ID); | |
result = await query.ToListAsync(); | |
Debug.Assert(result.Count == 1); | |
} | |
} | |
} | |
public class Image | |
{ | |
[PrimaryKey, AutoIncrement, Indexed, ] | |
public int ID { get; set; } | |
[Indexed] | |
public string ImageName { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment