This is a migrated thread and some comments may be shown as answers.

Flattening out a SINGLE object?

1 Answer 36 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 25 Jul 2011, 03:40 PM
I can flatten out a collection in a linq query to an Anon Type list like this
using (AuthDB.Model.Context context = new AuthDB.Model.Context()) {
            encounters = (from e in context.EtEncounters.ToList()
                          where e.EncounterName.ToLower().Contains(searchText)
                          select new {
                              ID = e.EncounterID,
                              Name = Server.HtmlEncode(e.EncounterName),
                              Status = "complete",
                              PatientType = "Simulation",
                              ObjectiveType = e.EtObjectiveType.Name
                          }).ToList();
        }
...and that works

But how do I do that with a .SingleOrDefault() query?  Like I have my object, but how do I transform it without creating an entire class file to just hold the one tiny object?

Steve

1 Answer, 1 is accepted

Sort by
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 25 Jul 2011, 04:07 PM
Oh wait, I got it with Dynamics

dynamic flatEncounter;
 
using (AuthDB.Model.Context context = new AuthDB.Model.Context()) {
    encounter = context.EtEncounters.SingleOrDefault(x => x.EncounterID == id);
 
    flatEncounter = new {
                          Amount = 108,
                          Message = "Hello"
                        };
}
 
return flatEncounter;
Tags
General Discussions
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Share this question
or