我创建了一个viewModel ClientViewModel:
public class ClientViewModel
{
public Client client
{
get;
set;
}
public SelectList RestrictionList
{
get;
set;
}
}
和一个带有create方法的控制器:
[HttpGet]
public ActionResult Create()
{
ClientViewModel model = new ClientViewModel();
model.client = new Client();
model.RestrictionList = GetRestrictions(); // your code to return the select list
return View("Edit", model);
}
这里是私有函数GetRestrictions():
private SelectList GetRestrictions() {
var RestrLst = new List<string>();
var RestrQry = from d in db.Restrictions//Here is my error of metadataException
orderby d.name
select d.name;
RestrLst.AddRange(RestrQry.Distinct());
return new SelectList(RestrLst);
}
}
在我的数据库中检索限制时出现错误。
有人可以帮我找出问题所在吗?
感谢您的帮助!