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 6558835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:14:54+00:00 2026-05-25T13:14:54+00:00

I have a fairly unique situation, I have never needed to this before anyways.

  • 0

I have a fairly unique situation, I have never needed to this before anyways. I have a Linq query that returns data from a database using EF4.1. I want to create multiple similar (same signature) anonymous (or even named if necessary) results from each query result.

Here’s the code i’m using now:

var data = getMyData().Select(x => 
              new 
              {
                GoalName = x.GoalType.Name, 
                Start = x.StartDate, 
                End = x.EndDate, 
                x.StartValue, 
                x.CheckIns
              }).ToList();

var r1 = data.Select(x => 
              new 
              { 
                title = x.GoalName, 
                start = x.Start.ToString(), 
                end = x.End.ToString(), 
                className = "hidden", 
                type = "goal"
              });

var r2 = data.Select(x => 
              new 
              { 
                title = string.Format("Start: {0:0.##}", x.StartValue), 
                start = x.Start.ToString(), 
                end = x.Start.ToString(), 
                className = "", 
                type = "" 
              });

var r3 = data.Select(x => 
              new 
              { 
                title = "End", 
                start = x.End.ToString(), 
                end = x.End.ToString(), 
                className = "", 
                type = "" 
              });

var r4 = data.SelectMany(x => x.CheckIns)
           .Select(y => 
              new 
              { 
                title = y.CheckInValue.Value.ToString(), 
                start = y.CheckInDateTime.ToString(), 
                end = y.CheckInDateTime.ToString(), 
                className = "", 
                type = "" 
              });

var result = r1.Union(r2).Union(r3).Union(r4);

Now maybe this is as good a way as any, but I can’t help feeling that i’m missing something.

Is there a better solution?

  • 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-05-25T13:14:54+00:00Added an answer on May 25, 2026 at 1:14 pm

    What you have is actually OK I think.

    But StevenzNPaul’s suggestion not that bad, here’s how you can use the let keyword to store the different projections, then select the results individually (for brevity, I did not project all the fields, but you get the point):

    var query = from x in data
                let result1 = new {title = x.GoalName, start = x.Start}
                let result2 = new {title = string.Format("Start: {0:0.##}", x.StartValue), start = x.Start}
                let result3 = new {title = "End", start = x.End}
                let checkins = x.CheckIns.Select(checkin => new { title = "...", start = checkin.Start })
                from result in new[] { result1, result2, result3 }.Concat(checkins)
                select result;
    

    Obviously, whether this is better is a matter of preference. Also, this will result in a different ordering, which may or may not be a problem for you.

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

Sidebar

Related Questions

I have a fairly complex SQL query that pulls different types of products from
I have a fairly standard inheritance situation in my current LINQ-to-SQL project. I have
I have a fairly unique situation trying to map a single table to multiple
I have a fairly unique situation with Asp.Net. An admin user must create any
I have the following SQL statement which returns Not unique table/alias . I'm fairly
this is my first posted question. I have a fairly complicated OQL query which
Fairly simple question that I can't remember. We have three environments: Local machine (unique
I have a LINQ query: var result = from mt in MessageTypes join mtfmt
I have a fairly small MySQL database (a Textpattern install) on a server that
I have a fairly standards compliant XHTML+CSS site that looks great on all browsers

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.