0

I have class called Dossier which is my Base Class and a classes called PensioenDossier and AovDossier which inherits Dossier.

public partial class Dossier
{
    public int ID { get; set; }
    public int ProductID { get; set; }
    public string Nummer { get; set; }
}
public partial class PensioenDossier : Dossier
{
    public decimal Premie { get; set; }
    public decimal? PartnerPensioen { get; set; }
}
public partial class AovDossier : Dossier
{
    public decimal VerzekerdKapitaal { get; set; }
    public decimal? MaandPremie { get; set; }
}

Now I have a process where I select a Product(Pensioen/AOV) and want to filter based on the selected Product. So I get the all Dossiers by

Context.Dossiers

I then filter on ProductID. And if its Pensioen I would like to filter on for example "Premie" and if it is AOV then I want to filter on "MaandPremie". But since I got Context.Dossiers I am wondering if it possible to filter on the derived class properties?

Bartvandee
  • 289
  • 3
  • 19

1 Answers1

1

Depending on how time critical things are, here is one way;

var allDossiers = Context.Dossiers.AsQueryable();
var filteredPensioenDossiers = allDossiers.OfType<PensioenDossier>().Where(d => d.Premie > 1000);
var filteredAovDossiers = allDossiers.OfType<AovDossier>().Where(d => d.MaandPremie.HasValue);

var allFilteredDossiers = (filteredPensioenDossers as Dossier).Concat(filteredAovDossiers as Dossier);
Mattias Åslund
  • 3,877
  • 2
  • 18
  • 17
  • Thank you, this worked for me :) all I needed was the allDossiers.OfType() since its either Pensioen or AOV. – Bartvandee May 11 '16 at 15:16