大家好,所以这里是我的基本EF类结构:
public abstract class StandardEngineeredModel
{
[Key]
public string ModelNumber { get; set; }
public int VoltageInput { get; set; }
}
public class DualRatedInputEngineeredModel : StandardEngineeredModel
{
public int SinglePhaseVoltageInput { get; set; }
public string SinglePhaseHzInput { get; set; }
public decimal SinglePhaseAmpsInput { get; set; }
public bool SeparateInput { get; set; }
}
我的背景:
public class LabelPrintingContext : DbContext
{
public virtual DbSet<StandardEngineeredModel> StandardEngineeredModels { get; set; }
}
我要做的是查询StandardEngineeredModel。以下是我尝试的查询示例:
public StandardEngineeredModel GetEngineeredOrder(string modelNumber)
{
using (context = new LabelPrintingContext())
{
return (from s in context.StandardEngineeredModels
where s.ModelNumber == modelNumber
select s).FirstOrDefault();
}
}
但执行此操作时,它表示无效的列名SeparateInput似乎正在发生,因为由于从其继承的DualRatedInputEngineeredModel而将额外的列添加到我的StandardEngineeredModels表中。不确定如何解决这个问题,我不想返回Iqueryable,但无论我尝试什么,它告诉我SeparateInput是一个无效的列名。
我也尝试先抛出它并得到同样的错误:
public StandardEngineeredModel GetEngineeredOrder(string modelNumber)
{
using (context = new LabelPrintingContext())
{
return (from s in context.StandardEngineeredModels.OfType<StandardEngineeredModel>()
where s.ModelNumber == modelNumber
select s).FirstOrDefault();
}
}
我需要制作DTO或其他东西吗?我这样做完全错了吗?
提前感谢任何意见/帮助!