When I try to query using IQueryable , I receive the following error:
Error 3 The type 'T' should be a reference type in order to use it as parameter 'TEntity' in the generic type or method 'System.Data.Entity.DbContext.Set ()'
1st - I have 3 entities
Parent class that is an interface: does not have a table in it for it
public interface IParentEquipment
{
string DaughterOperativeNumber { get; }
}
and two child classes that are abstract:
[Table("TB_EQPT_SUB")]
public abstract class EquipmentSub : IParentEquipment
{
[Column("OPERATIVE_NUMBER")]
public string OperativeNumber { get; set; }
public string DaughterOperativeNumber
{
get { return this.OperativeNumber ; }
}
}
[Table("TB_EQPT")]
public abstract class Equipment : IParentEquipment
{
[Column("OPERATIVE_NUMBER")]
public string OperativeNumber { get; set; }
public string DaughterOperativeNumber
{
get { return this.OperativeNumber ; }
}
}
I have a method to fetch a EquipmentSub or Equipment via the operative number.
public T FindGenericEquipmentByOperativeNumber<T>(string operativeNumber) where T : IParentEquipment
{
IQueryable<T> query = _ctx.Set<T>();
QueryFilter<T> queryFilter = new QueryFilter<T>();
query = query.Where(s => !(s.DaughterOperativeNumber.Equals(operativeNumber)));
query = query.Where(queryFilter.GetFilter);
return query.Single();
}
I noticed that if I change my IParentEquipment interface, for an abstract error some.
public abstract class IParentEquipment{
}
Why can not I use an interface in my query?