Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying bool column always returns false

I'm using SQLite in my project and to connect to DB I use sqlite-net library. I have created a model:

internal class Product
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    public string Name { get; set; }

...

    public bool IsDefault { get; set; }
}

There are a few records in database - some have IsDefault column value set to true, some to false. However, when I try to query records like this:

var result = dc.Table<Product>().ToArray();

every record has IsDefault set to false. Inserting a record works fine, but querying it do not.

When I changed column type to bool? in model, it returns null.

EDIT---- What is weird is when I execute query

var t = dc.Table<Product>().Where(i => i.IsDefault == true).ToArray();

It returns me correct number of records, but even so every item of array has IsDefault set to false.

like image 873
ksalk Avatar asked Aug 20 '13 12:08

ksalk


1 Answers

Edited:

SqlLite has some limited types, bool is not one of them: http://www.tutorialspoint.com/sqlite/sqlite_data_types.htm

You have to use Int (0 / 1)

like image 50
user149113 Avatar answered Nov 09 '22 08:11

user149113