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
- Fix-Gradient effect turning to gray in after effects
- How to blur an image in python?
- ModuleNotFoundError: No module named 'whois' in Python GoviralHost Without Terminal
- How to Convert Image to Pencil Sketch in Python?
- AttributeError: module 'urllib' has no attribute 'request' - Python
- How to Extract audio from video files using python?
- PermissionError: [Errno 13] Permission denied: 'shampoo_sales.csv' - Python
- [WinError 145] The directory is not empty: 'FolderPath' - Python
Related Article