I'm using entity framework 6 to develop my c# application. I have named my data model as Allocation model and I have a table called JobTable.
My Database model class looks like this
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; }
}
and my job header looks like this
My Job header class looks like this Job jeader class is the class generated from entity frame work model for my table 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; }
}
How can I query data for sql queries like following.?
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();
}
Usually I get data for an object like above. but i need to get a single field without reading data to an object of the class created for Table in data model getting all row details for the object. How to handle a normal query in this way ?