question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filter dynamic column with ExpressionMethod throws Exception

See original GitHub issue

LinQToDb: 2.7.4 Firebird: 2.1

Hi,

is it possible to use dynamic columns with ExpressionMethods? I have the following:

[Table("PERSON")]
public class Person{
    [COLUMN("AGE")]
    public int Age {get; set;}
    [COLUMN("NAME")]
    public string Name {get; set;}

    [ExpressionMethod(nameOf(GetTypeExpr), IsColumn = true)]
    public int Type {get; set;}

    public static Expression<Func<Person, int>> GetTypeExpr(){
        return p => (Sql.Property<int>(p, "OPTIONS")& 0xF);
    }
}

The table looks like this:

Tablename PERSON, Columns: AGE (int), NAME (int), OPTIONS (string)

The real context looks complexer…

This works:

using(var db = new MyDb()){
    var result = db.GetTable<Person>().ToList();
}

result has all Types set with the right values. But if I put in a Where filter, it throws an ArgumentOutOfRangeException (TableContext.cs line 335)

using(var db = new MyDb()){
    var result = db.GetTable<Person>().Where(p => p.Type == 4).ToList();
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
sdanylivcommented, Sep 26, 2019

Sql.Expr<int>("BIN_AND(OPTIONS, 1)")

0reactions
frankiDotNetcommented, Sep 26, 2019

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create dynamic entity framework filter expression ...
1 Answer 1 ... Yes, you can. One approach I've used uses an object which is the same as your return type as...
Read more >
DataGrid dynamic column filter - Radzen.Blazor Components
I try to initial the data in the OnInitializedAsync function and remove the LoadData function, and it throws the following error when I...
Read more >
Help! How to use Filter Query dynamically??
I am new to Power Automate and have a question about how to use Filter Query dynamically. For example, the below shows I...
Read more >
Filter records based on dynamic column values - Help
i want to filter to filter the records based on column “department” which is dynamic,where the values under that column may increase. image....
Read more >
DataColumn.Expression Property (System.Data)
Gets or sets the expression used to filter rows, calculate the values in a column, or create an aggregate column.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found