DynamicQuery creation

Posts   
 
    
jovball
User
Posts: 443
Joined: 23-Jan-2005
# Posted on: 16-Sep-2013 13:42:29   

I'm just now getting started with QuerySpec. I am trying to use the FetchAsDataTable method because we need DataSets (with related DataTables) for some report creation tasks.

I'm trying to do the equivalent of "Select * from Customers" with this code.

    
var qf = new QueryFactory();
            PredicateExpression filter = new PredicateExpression();
            filter.Add(CustomerFields.Country == country);

           DynamicQuery query = qf.Create()
               .Select(qf.Customer)
               .Where(filter);
            
            using (var adapter = new DataAccessAdapter())
            {
                DataTable table = adapter.FetchAsDataTable(query);          
            }

The exception message that I get is:

"Couldn't create any correlation filter lambda because the nested query didn't have any correlation filters. Please specify a filter in the nested query to tie the nested query to the parent query"

What am I missing?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Sep-2013 05:49:41   

Which LLBLGen pro runtime library version (build no.) are you using?

Do you get the same exception is you use the following?

CustomerFields.CustomerId.NotIn(


            var qf = new QueryFactory();
            DynamicQuery query = qf.Create()
             .Select(qf.Customer)
             .Where(CustomerFields.Country.Equal(country));
            
            using (var adapter = new DataAccessAdapter())
            {
                DataTable table = adapter.FetchAsDataTable(query);          
            }
jovball
User
Posts: 443
Joined: 23-Jan-2005
# Posted on: 17-Sep-2013 13:22:10   

I am using 3.5.12.317 for this test.

I get the same exception with your code sample.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Sep-2013 17:00:25   

Could you please try regenerating the code into an empty folder to make sure all generated code are new, and no file was no overwritten?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39912
Joined: 17-Aug-2003
# Posted on: 18-Sep-2013 09:20:50   

jovball wrote:

I'm just now getting started with QuerySpec. I am trying to use the FetchAsDataTable method because we need DataSets (with related DataTables) for some report creation tasks.

I'm trying to do the equivalent of "Select * from Customers" with this code.

    
var qf = new QueryFactory();
            PredicateExpression filter = new PredicateExpression();
            filter.Add(CustomerFields.Country == country);

           DynamicQuery query = qf.Create()
               .Select(qf.Customer)
               .Where(filter);
            
            using (var adapter = new DataAccessAdapter())
            {
                DataTable table = adapter.FetchAsDataTable(query);          
            }

The exception message that I get is:

"Couldn't create any correlation filter lambda because the nested query didn't have any correlation filters. Please specify a filter in the nested query to tie the nested query to the parent query"

What am I missing?

You're specifying an EntityQuery<Customer> in the projection. The correct query is:


var qf = new QueryFactory();
var query = qf.Customer
                .Where(CustomerFields.Country == country)
                .Select(Projection.Full);

using (var adapter = new DataAccessAdapter())
{
    DataTable table = adapter.FetchAsDataTable(query);          
}

See: http://www.llblgen.com/documentation/4.0/LLBLGen%20Pro%20RTF/hh_goto.htm#Using%20the%20generated%20code/QuerySpec/gencode_queryspec_projections.htm

Frans Bouma | Lead developer LLBLGen Pro
jovball
User
Posts: 443
Joined: 23-Jan-2005
# Posted on: 19-Sep-2013 19:57:35   

Yes, that solves my problem with the exception (the question in this thread).

I was hoping that the FetchAsDataTable with the DynamicQuery would be the answer I'm looking for in another thread I posted (http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=22163). That is, how to return custom entity fields as part of a DataTable.

I now know that QuerySpec doesn't help me there. (Or at least, that I don't know enough to make it do that yet!)