I have a class structure in the following form:
public class Pessoa
{
public int Id {get; set;}
public string Nome {get; set;}
}
public class Membro : Pessoa
{
public int CargoId {get; set;}
public Cargo Cargo {get; set;}
}
public class MembroTemp : Pessoa { }
My database has the Pessoas
table aggregating the data for the two classes and thus has the Discriminator
field.
Onaqueryscreen,Ineedtobringbothdatatypes,ofclassMembro
andMembroTemp
.And,forrecordsoftypeMembro
,IneedtogettheCargo
tothendemonstrateinthatquery.
SoIthoughtofsomethinglike:
var items = repository.Pessoas.Include(x => x.Cargo).OrderBy(x => x.Nome);
But of course it does not give or compile because the Pessoa
class does not have the Cargo
property, it is Membro
. Not even if I force it with a Include("Cargo")
will not work, of course.
I tried a unified search instead of doing it separately:
var membros = repository.Membros.Include(x => x.Cargo).OrderBy(x => x.Nome);
var membrosTemp = repository.MembrosTemp.OrderBy(x => x.Nome);
Because in my Action
I do filters and order by field . In the case of sorting I do not know how to unify the records but respect the sorting.
If I make separate requests I will end up with a result of type:
+-----------------------------+
|ID | Nome | Discriminator|
+-----------------------------+
| 1 | Fulano 1 | Membro |
| 2 | Fulano 2 | Membro |
| 3 | Fulano 1 | MembroTemp |
| 4 | Fulano 2 | MembroTemp |
+-----------------------------+
And this is not a perfect name ordering.
How can I deal with this situation?