I have a data session model which contains many different types of applicants. All of these have FirstName and LastName properties which I would like to display in a razor view.

var applicant = model.Lead ??
                model.Drivers.FirstOrDefault() ??
                model.Loans.FirstOrDefault() ?? 

At first glance, I would use inheritance, except that these are classes in an EF database, not sure how to setup a parent class.

Is there a clean way to do this or am I stuck with something like this?

dynamic applicant = new ExpandoObject();

if (model.Lead != null) {
   applicant.FirstName = model.Lead.FirstName;
   applicant.LastName = model.Lead.LastName;
} else if ( model.Drivers.Any() ) {
   var first = model.Drivers.FirstOrDefault();
   applicant.FirstName = first.FirstName;
   applicant.LastName = first.LastName;
} else if ...

Related posts

Recent Viewed