我是 MVC 和 EF 的新手,并且有一段时间让 EF 查询工作,特别是使用 EF key=""。添加一些测试代码后,这里返回的错误是 'The name idAddress does not exist in the current context'。Address 表上有一个名为 idAddress - identty int 的主键
我已经阅读了该网站上的许多建议,但无法超越这一点。
private motion_care_360Entities db = new motion_care_360Entities();
public ActionResult GetItems(GridParams g)
{
var list = db.Addresses.Include("AddressCountry").Include("AddressState").Include("AddressType").AsQueryable();
var list1 = list.OrderBy(o => idAddress).ToList();
var l1 = list1[0].AddressState.State;
return Json(new GridModelBuilder<Address>(list, g)
{
Key = "idAddress", // needed when using Entity Framework, usually it's Id
// If you're using EF, it's needed so that the data will be ordered by it before paging it
Map = o => new
{
AddressTypeType = o.AddressType.Type,
AddressStateState = o.AddressState.State,
AddressCountryCountry = o.AddressCountry.Country,
o.City,
}
}.Build());
}
}