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

This problem occurs when I attempt to utilize the Dynamic Linq library in my code.

'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

this is my code, too.

 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

My knowledge of dynamic Linq is limited, however based on 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

Try this, please:

1. Is the UserId column an integer rather than a string? Perhaps you should employ:

    string filter = "UserId='15'";

2.) Try adding a second input that includes the filter parameter:

    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

Do 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 understand that this isn't dynamic linq, but as long as your data structure is sound, it should still function. Please publish it.



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