Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery, DbRawSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to local data. For WPF bind to DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList()
I got this following error “Data binding to a store query is not support”, when I tried to bind the dropdownlist using the entity framework model object.
Problem:
public void LoadProductsDropDownList()
{
cboProducts.DataTextField = "Name";
cboProducts.DataValueField = "ProductId";
cboProducts.DataSource = db.Products;
cboProducts.DataBind();
ListItem li = new ListItem("Select Product", "-1");
cboProducts.Items.Insert(0, li);
}
Solution:
I found the cause of this error because of data binding directly is not supported. Instead of that we need to convert to list and then bounded to the dropdownlist.
public void LoadProductsDropDownList()
{
cboProducts.DataTextField = "Name";
cboProducts.DataValueField = "ProductId";
cboProducts.DataSource = db.Products.ToList();
cboProducts.DataBind();
ListItem li = new ListItem("Select Product", "-1");
cboProducts.Items.Insert(0, li);
}
Post your comments / questions
Recent Article
- How to create custom 404 error page in Django?
- Requested setting INSTALLED_APPS, but settings are not configured. You must either define..
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
Related Article