sir can anyone lend me a hand in fixing my program.. im using kendo ui in my asp.net mvc. the problem is the records in the database is not being display everytime i run the program it just display nothing.and indicate a error.. saying "{"The entity or complex type 'database.APPLICANT' cannot be constructed in a LINQ to Entities query."}"
here is my controller:
private IQueryable<APPLICANT> GetApplicant()
{
var applicants = (from a in dbContext.APPLICANTs
select a).Take(50).ToList();
return applicants as IQueryable<APPLICANT>;
}
public ActionResult GetApplicant([DataSourceRequest] DataSourceRequest request)
{
return Json(GetApplicant().ToDataSourceResult(request));
}
public ActionResult UpdateCustomer([DataSourceRequest] DataSourceRequest request, APPLICANT applicant)
{
var customerToUpdate = dbContext.APPLICANTs.First(app => app.APPLICANT_ID == applicant.APPLICANT_ID);
TryUpdateModel(customerToUpdate);
dbContext.SaveChanges();
return Json(ModelState.ToDataSourceResult());
}
public ActionResult InsertCustomer([DataSourceRequest] DataSourceRequest request, APPLICANT customerToAdd)
{
if (ModelState.IsValid)
{
dbContext.APPLICANTs.Add(customerToAdd);
dbContext.SaveChanges();
}
return Json(new[] { customerToAdd }.ToDataSourceResult(request));
}
public ActionResult DeleteCustomer([DataSourceRequest] DataSourceRequest request, APPLICANT applicant)
{
var customerToDelete = dbContext.APPLICANTs.First(app => app.APPLICANT_ID == applicant.APPLICANT_ID);
if (customerToDelete != null)
{
dbContext.APPLICANTs.Remove(customerToDelete);
dbContext.SaveChanges();
}
return Json(new[] { customerToDelete }.ToDataSourceResult(request));
}
my context:
public partial class APPLICANT
{
public int APPLICANT_ID { get; set; }
public string APPLICANT_LastName { get; set; }
public string APPLICANT_FirstName { get; set; }
public string APPLICANT_MiddleName { get; set; }
public string APPLICANT_Address { get; set; }
public string APPLICANT_City { get; set; }
public string APPLICANT_ZipCode { get; set; }
public string APPLICANT_Phone { get; set; }
public string APPLICANT_Email { get; set; }
}
index:
@{
ViewBag.Title = "Home Page";
}
<h2>@ViewBag.Message</h2>
@(Html.Kendo().Grid<KendoGridMvcCodeFirst.ViewModels.APPLICANT>()
.Name("APPLICANT")
.ToolBar(tb => tb.Create())
.Pageable()
.DataSource(dataSource => dataSource.Ajax()
.Model(model => model.Id(c => c.APPLICANT_ID))
.Read("GetAPPLICANT", "Home")
.Update("UpdateCustomer", "Home")
.Create("InsertCustomer", "Home")
.Destroy("DeleteCustomer", "Home"))
.Columns(cols =>
{
cols.Bound(c => c.APPLICANT_LastName).Width(200);
cols.Bound(c => c.APPLICANT_FirstName).Width(200);
cols.Bound(c => c.APPLICANT_MiddleName).Width(200);
cols.Bound(c => c.APPLICANT_Address);
cols.Bound(c => c.APPLICANT_City);
cols.Bound(c => c.APPLICANT_ZipCode);
cols.Bound(c => c.APPLICANT_Phone);
cols.Bound(c => c.APPLICANT_Email);
cols.Command(cmd =>
{
cmd.Edit();
cmd.Destroy();
});
})
)
*what is missing in my codes? thanks for those who can help