sqlite-net icon indicating copy to clipboard operation
sqlite-net copied to clipboard

LINQ Where() Does Not Work Well With Enums Decorated With the StoreAsTextAttribute

Open Allison-E opened this issue 7 months ago • 0 comments

Hi. Well done for the good work done here.

I discovered LINQ Where() doesn't correctly parse enums having the [StoreAsText] attributes. For example, let's say we have tables created from the following object:

[StoreAsText]
enum TransactionTypes
{
    Income,
    Expense,
}

class Transaction
{
    [PrimaryKey, AutoIncrement]
    public string Id { get; set; }
    public TransactionTypes Type { get; set; }
}

Fetching all income transactions using LINQ should look like this:

// Isolating the query so it can be inspected.
var query = database.Table<Transaction>().Where(t => t.Type == TransactionTypes.Income);
List<Transaction> transaction = await query.ToListAsync()

But this will return no item.

Inspecting query in the debug view as an Expression shows that it interprets the given predicate supposing that Transaction.Type would be stored as an integer, ignoring the StoreAsText attribute.

Query as inspected in the debug view

Allison-E avatar Jun 28 '24 09:06 Allison-E