I have a situration where I have a class
[Table("SomeTable")]
public Class Thing
{
[Key]
public int Id { get; set; }
public string Description { get; set; }
public int ImAForeignKey { get; set; }
public bool HasStuff { get; set; }
}
...
...
public class ugly
{
public Thing Thing { get; set; }
public List<Thing> LotsOfThings { get; set; }
}
Where Thing is some EF class representing a table in a database…
I then want to create a collection of ugly:
List<ugly> gruesome;
using (var db = new ThingyDatabase())
{
gruesome = db.Thing
.Where(r => r.HasStuff && r.ImAForeignKey == passedin.someFKvaluePassedIn )
.Select(r => new ugly {
Thing = passedin,
LotsOfThings = ??
})
.ToList();
}
...
I unsure about how I populate the ListOfTHings property…. or if I can do it this way… I have an id that I am scouring Thing with and this id (foreign key) can have multiple records within Thing but one of the records is going to be the parent record and the rest of them are children. So what I would end up with is a collection of things with their children… hope this helps.
Any thoughts?
I ended up doing the following:
It gives me what I need the parent(passedin) and the children(gruesome)
thanks all