Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Allison-E opened this issue Jun 28, 2024 · 0 comments

Comments

@Allison-E
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant