Dyamic Linq .Net 4 error 'userid' could not be resolved in the current scope or contex

.net-4.0 dynamic-linq entity-framework linq

Question

I am trying to use Dynamic Linq library in my code, but it gives this error

'UserId' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near simple identifier, line 6, column 1

and here is my code

 TestDB db = new TestDB();
        string filter = "UserId == 15";
        //var searchResult =
        GridView1.DataSource = from x in db.SearchSummaries.Where(filter)
                               select x;
        GridView1.DataBind();
1
0
9/28/2012 7:56:57 AM

Accepted Answer

Not so familiar with dynamic Linq but from your error message:

'UserId' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near simple identifier, line 6, column 1

Please try this:

1.) Is the column UserId a Integer and not a String? Mabye you need to use:

    string filter = "UserId='15'";

2.) Try to pass in the filter parameter as a second argument:

    GridView1.DataSource = db.SearchSummaries.Where("UserId = @0", 15); 

3.) I don't know if you are able to run "regular" Linq queries, but if you are, try:

    GridView1.DataSource = db.SearchSummaries.Where(search => search.UserId == 15);                               
    GridView1.DataBind();
2
9/27/2012 5:58:44 PM

Popular Answer

Try this:

TestDB db = new TestDB();
    string filter = "xi => xi.UserId == 15";
    //var searchResult =
    GridView1.DataSource = from x in db.SearchSummaries.Where(filter)
                           select x;
    GridView1.DataBind();

Or this:

TestDB db = new TestDB();
    string filter = "UserId=15";
    //var searchResult =
    GridView1.DataSource = from x in db.SearchSummaries.Where(filter)
                           select x;
    GridView1.DataBind();

EDIT: I realize this isn't dynamic linq...but it should work regardless as long as your data structure is correct. Could you post that?



Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow