Skip to main content

Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery, DbRawSqlQuery) is not supported

Error Description:

This error can occur when you use the Bind method with the non-evaluated / IQueryable Model (for example, a table from a data context) to bind a data-aware DevExpress MVC Extensions (grid-like, scheduler and tree list extensions) to data.

Controller:

public ActionResult GridViewPartial() {  
    EFDataContext db = new EFDataContext();  
    return PartialView(db.Table_Name);  
}  
Public Function GridViewPartial() As ActionResult  
    Dim db As New EFDataContext()  
    Return PartialView(db.Table_Name)  
End Function  

PartialView:

@Html.DevExpress().GridView(settings => {  
    ...  
}).Bind(Model).GetHtml()  
@Html.DevExpress().GridView( _  
    Sub(settings)  
    ...  
End Sub).Bind(Model).GetHtml()  

Solution:

To resolve this issue, you can use the ToList method to load/evaluate a Model.

Controller:

using System.Linq;  
...  
public ActionResult GridViewPartial() {  
    EFDataContext db = new EFDataContext();  
    return PartialView(db.Table_Name.ToList());  
}  
Imports System.Linq  
...  

Public Function GridViewPartial() As ActionResult  
    Dim db As New EFDataContext()  
    Return PartialView(db.Table_Name.ToList())  
End Function  

See Also: