QueryFactory syntax question

Posts   
 
    
Kevinksy
User
Posts: 27
Joined: 05-Jun-2013
# Posted on: 06-Jun-2013 21:26:45   

When I run this query on the database

select S.IS_END_STAGE
from stage s
where S.ID = 1653;

I get the result 1 of type Number.

I thought this query should produce the same result but it returns null.

using LLBL.FactoryClasses;
using SD.LLBLGen.Pro.QuerySpec;
using LLBL.HelperClasses;
...
            var qf = new QueryFactory();
            var q = qf.Stage.Select(() => new {isNextStageEndStage = StageFields.IsEndStage.ToValue<Int32>()}).Where(StageFields.Id == 1653);

This variation also produces the same null result:

            var q = qf.Create().Select(() => new {isNextStageEndStage = StageFields.IsEndStage.ToValue<Int32>()}).Where(StageFields.Id == 1653);

The watch on q yields this result at runtime:

q   {SELECT
    With projection: 
        Field: StageEntity.Id

WHERE
    PredicateExpression:
        PredicateExpression:
            Predicate:
                FieldCompareValuePredicate:
                    Field:
                        Field: StageEntity.Id
                    Equal
                        Constant: 1653
Additional information:
    Offset: 0
    Alias: ''
    CacheResultset: False
}   SD.LLBLGen.Pro.QuerySpec.DynamicQuery<<>f__AnonymousType0<int>>

What am I not doing correctly?

Specs: Visual Studio 2010 Professional version 10.0.40219.1 SP1Rel LLBLGen Pro Version 4.0 Final using the "as 32 bit application" shortcut Development Machine Windows 7 Professional- 64 bit - Service Pack 1 Target Database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production Project Settings: Target Framework LLBL Gen Pro Runtime Framework, target C#, .Net 4.0 Template Group Adapter, preset SD.Presets.Adapter.General

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Jun-2013 07:25:11   

In my opinion, your code should work:

var qf = new QueryFactory();
var q = qf.Create()
                .Select(() => new
                {
                    IsNextStageEndStage = StageFields.IsEndStage.ToValue<int>()                 
                })
               .Where(StageFields.Id == 1653);;

using (var adapter = new DataAccessAdapter())
{
    var results = adapter.FetchQuery(q);

    foreach (var r in results)
    {
        Console.WriteLine("{0}", r.IsNextStageEndStage );
    }
}

Some questions: - What is null? The whole results or just the resulting IsNextStageEndStage? - What is the Generated SQL - Are you sure that you are connected to the correct DB?

David Elizondo | LLBLGen Support Team