Lets say I have an entity which can reference other rows in its table, defined like this:
MyEntity
{
public string Id { get; set; }
public string ParentId { get; set; }
public bool isRelevant { get; set; }
public virtual List<MyEntity> Children
}
Attempting something like:
var result = await MyEntities
.SelectMany(o => new List<string> { o.Id, o.ParentId })
.ToListAsync();
This however results in a runtime error:
The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable'...
How can I select all of the MyEntity Id AND ParentId values as a single list without reverting to client-side evaluation?
To be clear, I would like the result from the database to be something like:
["Id1", "parentId1", "Id2", "ParentId2"]