Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8460955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:44:50+00:00 2026-06-10T13:44:50+00:00

I have the following partial query var finalResults = (from o in outerJoin orderby

  • 0

I have the following partial query

var finalResults =

    (from o in outerJoin
    orderby o.timeKey.timeKey.Year_Num, o.timeKey.timeKey.Month, o.Key.Key.PlantId, o.timeKey.timeKey.PhysicalUnitId
    select new
    {
        IndicatorName = IndicatorName,
        LocationName = o.timeKey.timeKey.PlantId,
        GroupingName = o.timeKey.timeKey.PhysicalUnitId,
        Year = o.timeKey.timeKey.Year_Num,
        Month = o.timeKey.timeKey.Month, 
        Numerator = o.timeKey.Key.Derate_Hours != null ? o.timeKey.Key.Derate_Hours ?? 0 : 0,
        Denominator = o.timeKey.timeKey.Hours - o.timeKey.Key.Derate_Hours ?? 0,
        Weight = o.timeKey.timeKey.NetMaximumCapacity,                         
    }).ToList();

The query works fine except that Month gives me a month and year in the format:

August 2012

and I need it in this format:

08

I changed my code as reflected below:

var finalResults =

    (from o in outerJoin
    orderby o.timeKey.timeKey.Year_Num, o.timeKey.timeKey.Month, o.Key.Key.PlantId, o.timeKey.timeKey.PhysicalUnitId
    select new
    {
        IndicatorName = IndicatorName,
        LocationName = o.timeKey.timeKey.PlantId,
        GroupingName = o.timeKey.timeKey.PhysicalUnitId,
        Year = o.timeKey.timeKey.Year_Num,
        Month = DateTime.ParseExact(o.timeKey.timeKey.Month.Split(' ')[0], "MMMM", CultureInfo.CurrentCulture).Month,
        Numerator = o.timeKey.Key.Derate_Hours != null ? o.timeKey.Key.Derate_Hours ?? 0 : 0,
        Denominator = o.timeKey.timeKey.Hours - o.timeKey.Key.Derate_Hours ?? 0,
        Weight = o.timeKey.timeKey.NetMaximumCapacity,                         
    }).ToList();

but now I receive the following error:

Unrecognized expression node: ArrayIndex

Is there a way to do what I am trying to do? Changing the format in the DB is not an option.

Here is the entire query:

protected IList<DataResults> QueryData(HarvestTargetTimeRangeUTC ranges)
{
    using (var context = new DataClassesDataContext(_connectionString))
    {
        context.CommandTimeout = 240;                
        const string IndicatorName = "{DFD88372-FB87-49AC-8576-68DCBE7B00E8}";

        List<string> typeCodes = new List<string>() { "D1", "D2", "D3", "DP", "PD", "DM", "D4" };
        DataResults endItem = new DataResults();
        List<DataResults> ListOfResults = new List<DataResults>();

        var results =

            (from v in context.vDimUnits
             join vf in context.vFactEnergyAllocations on v.UnitKey equals vf.UnitKey
             join vd in context.vDimGadsEvents on vf.GadsEventKey equals vd.GadsEventKey
             join vt in context.vDimTimes on vf.TimeKey equals vt.TimeKey
             where typeCodes.Contains(vd.GadsEventTypeCode) 
                && vt.Year_Num >= ranges.StartTimeUTC.Year 
                && vt.Year_Num <= ranges.EndTimeUTC.Year                        
                && v.PhysicalUnitId != "N/A"
                && v.PhysicalUnitId != "UNK"
                && v.PlantId != "UNK" 
                && v.NercUnitType != "WT"
             group vf by new { v.PlantId, v.PhysicalUnitId, v.NetDependableCapacity, vt.Year_Num, vt.Month } into groupItem
             select new
             {
                 groupItem.Key.Year_Num,
                 groupItem.Key.Month,
                 groupItem.Key.PhysicalUnitId,
                 groupItem.Key.NetDependableCapacity,
                 Derate_Hours = groupItem.Sum(x => (float?)x.AllocatedEnergyMwh / groupItem.Key.NetDependableCapacity),
                 groupItem.Key.PlantId,
                 Unit = groupItem.Count()
             });

        var resultHours =

            (from f in
            (from vt in context.vDimTimes
            from v in context.vDimUnits
            where vt.Year_Num >= ranges.StartTimeUTC.Year
                && vt.Year_Num <= ranges.EndTimeUTC.Year 
                && v.PhysicalUnitId != "N/A" 
                && v.PhysicalUnitId != "UNK" 
                && v.PlantId != "UNK" 
                && v.NercUnitType != "WT"
            select new { v.PlantId, v.PhysicalUnitId, vt.Year_Num, vt.Month, vt.TimeKey, v.NetMaximumCapacity }).Distinct()
             group f by new { f.PhysicalUnitId, f.Year_Num, f.Month, f.PlantId } into groupItem
            select new
            {
                 groupItem.Key.PhysicalUnitId,
                 groupItem.Key.Year_Num,
                 groupItem.Key.Month,
                 groupItem.Key.PlantId,
                 groupItem.First().NetMaximumCapacity,
                 Hours = groupItem.Count()
            });

        var serviceHrsResults =

            (from v in context.vDimUnits
             join vf in context.vFactEnergyAllocations on v.UnitKey equals vf.UnitKey
             join vt in context.vDimTimes on vf.TimeKey equals vt.TimeKey
             join vus in context.vDimUnitStates on vf.UnitStateKey equals vus.UnitStateKey

             where vus.UnitStateType != "Active" 
                && vt.Year_Num >= ranges.StartTimeUTC.Year 
                && vt.Year_Num <= ranges.EndTimeUTC.Year
                && v.NetDependableCapacity != 0 
                && v.PhysicalUnitId != "N/A" 
                && v.PhysicalUnitId != "UNK" 
                && v.PlantId != "UNK" 
                && v.NercUnitType != "WT"

             group vf by new { v.PlantId, vt.Year_Num, vt.Month, v.PhysicalUnitId, v.NetDependableCapacity } into groupItem

             select new
             {
                 groupItem.Key.Year_Num,
                 groupItem.Key.Month,
                 groupItem.Key.PhysicalUnitId,
                 groupItem.Key.NetDependableCapacity,
                 groupItem.Key.PlantId,
                 Unit = groupItem.Count()
             });

        var outerJoin1 =

            (from h in resultHours
             join u in results on new { h.PhysicalUnitId, h.Year_Num, h.Month } equals new { u.PhysicalUnitId, u.Year_Num, u.Month } into outer
             from grouping in outer.DefaultIfEmpty()
             select new { timeKey = h, Key = grouping });

        var outerJoin2 =

            (from h in resultHours
             join s in serviceHrsResults on new { h.PhysicalUnitId, h.Year_Num, h.Month } equals new { s.PhysicalUnitId, s.Year_Num, s.Month } into outer2
             from grouping in outer2.DefaultIfEmpty()
             select new { timeKey = h, Key = grouping });

        var outerJoin =

            (from a in outerJoin1
             join b in outerJoin2 on new { a.timeKey.PhysicalUnitId, a.timeKey.Year_Num, a.timeKey.Month } equals new
             {
                 b.timeKey.PhysicalUnitId,
                 b.timeKey.Year_Num,
                 b.timeKey.Month
             } into outer
             from grouping in outer.DefaultIfEmpty()
             select new { timeKey = a, Key = grouping }).Distinct();


        var finalResults =

            (from o in outerJoin
             orderby o.timeKey.timeKey.Year_Num, o.timeKey.timeKey.Month, o.Key.Key.PlantId, o.timeKey.timeKey.PhysicalUnitId
             select new
             {
                IndicatorName = IndicatorName,
                 LocationName = o.timeKey.timeKey.PlantId,
                 GroupingName = o.timeKey.timeKey.PhysicalUnitId,
                 Year = o.timeKey.timeKey.Year_Num,
                 Month = DateTime.ParseExact(o.timeKey.timeKey.Month.Split(' ')[0], "MMMM", CultureInfo.CurrentCulture).Month,
                 Numerator = o.timeKey.Key.Derate_Hours != null ? o.timeKey.Key.Derate_Hours ?? 0 : 0,
                 Denominator = o.timeKey.timeKey.Hours - o.timeKey.Key.Derate_Hours ?? 0,
                 Weight = o.timeKey.timeKey.NetMaximumCapacity,                         
                 }).ToList();

        for (int counter = 0; counter < finalResults.Count; counter++)
        {
            var item = finalResults[counter];
            endItem = new DataResults();
            ListOfResults.Add(endItem);
            endItem.IndicatorName = IndicatorName;
            endItem.LocationName = item.LocationName;
            endItem.GroupingName = item.GroupingName;
            endItem.Year = item.Year;
            endItem.Month = item.Month.ToString();
            endItem.Numerator = item.Numerator;
            endItem.Denominator = item.Denominator;
            endItem.Weight = item.Weight.Value;                    
        }
        return ListOfResults;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:44:51+00:00Added an answer on June 10, 2026 at 1:44 pm

    We still don’t really have much context, but I’ll guess at an appropriate answer anyway 🙂

    If you’re trying to do a lot of work within a query expression which is being translated to SQL, you may find it’s better to split the query into two parts:

    • The part done in SQL, with as much filtering as possible and only specifying the data you need, but in a “raw” format
    • A part done in LINQ to Objects, which can use any .NET methods you need.

    You use AsEnumerable to effectively flip from using the methods in Queryable to the ones in Enumerable. So you might have:

    var sqlQuery = from ...
                   orderby ...
                   select ...;
    
    var finalQuery = sqlQuery.AsEnumerable().Select(entry => new { 
                         // Call whatever methods you like in here
                     });
    

    This avoids having to ask the LINQ provider to generate SQL to emulate things like this:

    DateTime.ParseExact(o.timeKey.timeKey.Month.Split(' ')[0], "MMMM", 
                        CultureInfo.CurrentCulture).Month,
    

    It also means that you can write helper methods which are easily tested outside your query:

    var finalQuery = sqlQuery.AsEnumerable().Select(entry => new { 
                         Month = ConvertYearMonthToMonthNumber(entry.Month),
                         ...
                     });
    

    Note that CultureInfo.CurrentCulture may very well be the wrong culture here, unless you really know that the data stored in your database is in the same culture as your user, which may not be the invariant culture. I think it’s much more likely that you really want to use the invariant culture… or just use Calendar.MonthNames.IndexOf(month).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following: var db = new datesDataContext(); var query = from ord
I have the following partial. It can be called from three different times in
I have the following partial view: @model IEnumerable<Foo> <div id=foo> @foreach (var foo in
The following query is not working from visual Studio: var query = this.ObjectContext.Questions.Include(AnswerKey).Where(o =>
I have the following code: public partial class queryTerm : System.Web.UI.UserControl { private static
In my rails view(index.html.erb), i have following structure <div> <%= render :partial => create
I have the following code in a partial view (using Spark): <span id=selectCount>0</span> video(s)
in a partial view I have the following: <%Html.RenderAction(MVC.User.GetComments(Model.UserGroupName)); %> can I render a
I have the following inide my Page_Load on an aspx.cs file: public abstract partial
I have in my app/views/bar/index.html.haml the following %p= render partial: 'foo', collection: @foos the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.