1

Work on asp.net mvc5 with ef version 6.1.3 and Unity repository .Say there is a model with a base type of SmartDevice and three derived types of SmartRainbow, SmartRouter, SmartSwitch. Like bellow:

private readonly IRepositoryAsync<SmartDevice> _smartDeviceRepository;

constructor has bellow syntax

_smartDeviceRepository = unitOfWork.RepositoryAsync<SmartDevice>();

SmartDevice

 public class SmartDevice : Entity
    {
        #region Primitive Properties
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int DeviceId { get; set; }

        public DeviceType DeviceType { get; set; }
        #endregion



        #region  Navigation Properties

        public virtual ICollection<DeviceStatus> DeviceStatus { get; set; }

        #endregion
    }

SmartSwitch

  public class SmartSwitch : SmartDevice
    {
        #region  Navigation Properties      
        public virtual ICollection<Channel> Channels { get; set; }              
        #endregion
    }

SmartRainbow

 public class SmartRainbow : SmartDevice
    {
        #region  Navigation Properties

        public virtual ICollection<RgbwStatus> RgbwStatuses { get; set; }

        #endregion
    }

By querying SmartDevice I get all entities my syntax is bellow:

var temp = _smartDeviceRepository.Query().Select().ToList();

problem is through every entity of above result will be of type SmartRainbow or SmartRouter or SmartSwitch I can not load any single inherited type properties and navigation propreties.

Using the bellow syntax I failed to load the navigation property

var temp = _smartDeviceRepository.Query().Select().OfType<SmartSwitch>().ToList(); 
  • Can not load SmartSwitch property Channels?
  • Can not use include after the OfType method?
  • Why can not have include after the OfType?
shamim
  • 6,640
  • 20
  • 85
  • 151
  • Possible duplicate of [Entity Framework 6 - inheritance and navigation properties on base class](http://stackoverflow.com/questions/24488653/entity-framework-6-inheritance-and-navigation-properties-on-base-class) – Nkosi Apr 07 '16 at 12:11

0 Answers0