0
When trying to make a query using Iqueryable, I get the following error:
Error 3 The type’T' must be a Reference type in order to use it as Parameter 'Tentity' in the Generic type or method 'System.Data.Entity.DbContext.Set()'
1 - I have 3 entities
parent class which is an interface: does not have a base table for it
public interface IParentEquipment
{
string DaughterOperativeNumber { get; }
}
and two daughter 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 possess a method to seek one Equipmentsub or Equipment through the operating 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 realized that if I change my interface Iparentequipment, for a Abstract the error adds up.
public abstract class IParentEquipment{
}
Why can’t I use an interface in my query?
the syntax gets:
where T : class, IParentEquipment
, thanks helped me a lot =)– Mik3i4a5