Linq Where with Group By problem

Posts   
 
    
hokus
User
Posts: 2
Joined: 27-Jun-2011
# Posted on: 27-Jun-2011 13:02:41   

SD.LLBLGen.Pro.ORMSupportClasses.NET20 2.0.50727 SD.LLBLGen.Pro.DQE.SqlServer.NET20 2.0.50727 SD.LLBLGen.Pro.LinqSupportClasses.NET35 2.0.50727

LLBL GEN 2.6 on sqlserver 2005

I'm trying to use linq query with "Where" and "Group By". I have such a code with "Where":

private IQueryable<CustomerTrafficDataEntity> Search(CustTrafficSearchCriteria searchCriteria)
    {
        var data = _metaData.CustomerTrafficData.AsQueryable();

        if (searchCriteria.ModelLineId.HasValue)
            data = data.Where(x => x.CtdMdlineId == searchCriteria.ModelLineId);
        if (searchCriteria.DateFrom.HasValue)
            data = data.Where(x => x.CustomerTrafficSheet.CtsDate >= searchCriteria.DateFrom.Value);
        if (searchCriteria.DateTo.HasValue)
            data = data.Where(x => x.CustomerTrafficSheet.CtsDate <= searchCriteria.DateTo.Value);

        return data;
    }

Then I use this:

    protected void btnGenerate_Click(object sender, EventArgs eventArgs)
    {
        // Prepare Search Criteria
        CustTrafficSearchCriteria searchCriteria = GetSearchCriteria();
        
        var data = this.Search(searchCriteria);

        switch (ddlReportType.SelectedValue)
        {
            case "Traffic":
                var q = data.GroupBy(x => x.CustomerTrafficSheet.CtsDate).Select(
                    g => new Result {Date = g.Key, Total = g.Sum(x => x.CtdTraffic ?? 0)});//.OrderBy(o => o.Date);
                break;
        }

        Chart.DataBind();
    }

But "q" result throws Exception...

base {SD.LLBLGen.Pro.ORMSupportClasses.ORMException} = {"An exception was caught during the execution of a retrieval query: The multi-part identifier \"LPLA_2.CTS_Date\" could not be bound.\r\nThe multi-part identifier \"LPLA_2.CTS_Date\" could not be bound.. Check InnerException, QueryExecuted and Parameters o...

and sql query:

"\r\n\tQuery: SELECT [LPA_L1].[CtsDate] AS [Date], [LPA_L1].[LPAV_] AS [Total] FROM (SELECT [LPA_L3].[CtsDate], SUM([LPA_L3].[LPAV_]) AS [LPAV_] FROM (SELECT [LPA_L4].[CTS_Date] AS [CtsDate], COALESCE([LPA_L5].[CTD_Traffic], @LO01) AS [LPAV_] FROM ( [HPL_SPEED].[dbo].[CustomerTrafficSheets] [LPA_L4]  RIGHT JOIN [HPL_SPEED].[dbo].[CustomerTrafficData] [LPA_L5]  ON  [LPA_L4].[CTS_Id]=[LPA_L5].[CTD_CTSId])) [LPA_L3] WHERE ( ( ( ( [LPLA_2].[CTS_Date] >= @CtsDate2)) AND ( [LPLA_2].[CTS_Date] <= @CtsDate3))) GROUP BY [LPA_L3].[CtsDate]) [LPA_L1]\r\n\tParameter: @LO01 : Int32. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 0.\r\n\tParameter: @CtsDate2 : DateTime. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 2011-06-23 00:00:00.\r\n\tParameter: @CtsDate3 : DateTime. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 2011-06-23 00:00:00.\r\n"
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 27-Jun-2011 13:33:01   
Frans Bouma | Lead developer LLBLGen Pro
hokus
User
Posts: 2
Joined: 27-Jun-2011
# Posted on: 30-Jun-2011 11:04:47   

So ?simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 30-Jun-2011 11:07:20   

hokus wrote:

So ?simple_smile

Sorry?

You didn't provide the information so we can't proceed with helping you. You now specified the .NET runtime versions. Please read the link I posted how to obtain the runtime library build nrs, so we know if you're on the latest build and which version you're using.

Frans Bouma | Lead developer LLBLGen Pro