这段代码有什么问题:
_department.valuemember = "id";
var query = db.table.asqueryable();
query = query.Where(d => d.departmentID == _depatment.SelectedValue as int? );
我收到此错误:无法创建类型为“System.Object”的常量值。此上下文仅支持原始类型(“例如 Int32、String 和 Guid”)。
我更改了代码并解决了问题:
int selectedvalue = int.parse(_department.selectedvalue.tostring());
query = query.Where(d => d.departmentID == selectedvalue );
谢谢卡梅隆 :)