【发布时间】:2013-11-20 13:42:24
【问题描述】:
public class EmployeeDetail
{
[Key]
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
[NotMapped]
public string FullName
{
get
{
return (this.FirstName + " " + this.MiddleName + " " + this.LastName).ToUpper();
}
}
}
创建动作方法
public ActionResult CreateEmploymentType()
{
PopulateEmployeeIdDropDownList();
return View();
}
填充方法
private void PopulateEmployeeIdDropDownList(object selectedEmployeeId = null)
{
var EmployeeIdQuery = from d in db.EmployeeDetails
orderby d.FullName
select d;
ViewBag.EmployeeId = new SelectList(EmployeeIdQuery, "EmployeeId", "FullName", selectedEmployeeId);
}
查看下拉列表
EmployeeName: @Html.DropDownListFor(model => model.EmployeeId, (SelectList)ViewBag.EmployeeId)
问题:
当我运行应用程序时,它会给出错误消息
LINQ to Entities 不支持指定的类型成员“FullName”。仅支持初始化程序、实体成员和实体导航属性。
【问题讨论】:
标签: c# asp.net asp.net-mvc razor