我正在使用实体框架 6 来开发我的 c# 应用程序。我已将我的数据模型命名为分配模型,并且我有一个名为 JobTable 的表。
我的数据库模型类看起来像这样
public partial class Allocation : DbContext
{
public Allocation()
: base("name=Allocation")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<JOB_Header> JOB_Header { get; set; }
}
我的工作标题看起来像这样
我的 Job 标题类看起来像这个 Job jeader 类是从我的表 Job_header 的实体框架工作模型生成的类
public partial class JOB_Header
{
public int JobID { get; set; }
public string CustomerCode { get; set; }
public string CustomerName { get; set; }
public string MobileNo { get; set; }
public string LocationCode { get; set; }
public System.DateTime JobDate { get; set; }
public bool Status { get; set; }
public string Remarks { get; set; }
}
如何查询以下 sql 查询的数据?
SELECT TOP 1 * FROM JOB_Header ORDER BY JOBID DESC;
select CustomerName from JOB_Header where JobID =1;
using (DataControllers.AllocationJAEntities = new DataControllers.Allocation())
{
JHeaderModel = JAEntities.JOB_Header.Where(a => a.JobID == 1).FirstOrDefault();
}
通常我会得到像上面这样的对象的数据。但我需要获取单个字段而不读取数据到为数据模型中为表创建的类的对象获取对象的所有行详细信息。如何以这种方式处理正常查询?