I have a rather unique situation, I have never had to do this anyway. I have a Linq query that returns data from a database using EF4.1. I want to create several similar (identical signatures) anonymous (or even named if necessary) results of each query result.
Here is 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, perhaps this is just as good as everyone, but I cannot help but feel that something is missing.
Is there a better solution?
source share