Tôi đã dành 2 ngày qua tự hỏi tại sao điều này không hiệu quả, nhưng đối với các bảng khác, nó hoạt động hoàn toàn tốt. Tôi thậm chí đã thử nghiệm mô hình khác của tôi có chứa nhiều lĩnh vực. BUt này cụ thể, ngay cả với ONLY 2 lĩnh vực không hoạt động. Tôi biết tôi có thể thiếu một phần rõ ràng, xin vui lòng giúp đỡ.Thành viên loại được chỉ định không được hỗ trợ trong LINQ to Entities. Chỉ những người khởi tạo, thành viên thực thể và thuộc tính điều hướng thực thể mới được hỗ trợ
Dưới đây là mẫu của tôi
public class ReceivedItem
{
public int ReceivedItemID { get; set; }
public int ItemID { get; set; }
}
ViewModel
public class ReceivedItemViewModel
{
public int ReceivedItemID { get; set; }
public int ItemID { get; set; }
}
khiển
[GridAction]
public ActionResult GetReceivedItems()
{
return View(new GridModel(GetReceivedItemsViewModels()));
}
private IQueryable<ReceivedItemViewModel> GetReceivedItemsViewModels()
{
return db.ReceivedItems
.Select(
c => new ReceivedItemViewModel
{
ItemID = c.ItemID
});
}
Xem
@(Html.Telerik().Grid<ReceivedItem>()
.Name("grdItems")
.DataBinding(binding => binding.Ajax()
.Select("GetReceivedItems", "Receiving"))
.DataKeys(keys => keys.Add(o => o.ItemID))
.Columns(cols =>
{
cols.Bound(c => c.ItemID);
})
.Pageable()
.Sortable()
.Groupable()
.Filterable()
)
Lỗi i đã sử dụng firebug:
The specified type member 'ReceivedItemID' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
Nó sẽ giúp biết nơi ngoại lệ xảy ra. Ngoại lệ này thường chỉ ra rằng bạn sử dụng một thực thể có giá trị nguyên thủy được mong đợi, như 'Where (a => a.Parent == parentObject)'. (Nên là 'Ở đâu (a => a.ParentId == parentId)'). –