c# - How to bind a DataSource to DataGridView or ListView -


i using 3 layered architecture entity framework 6.1 code-first

code in ui layer

datagridview1.datasource = _userbll.getusers(); 

code in business logic layer

public object getusers() {     return _userdal.getusers(); } 

code in data access layer

public object getusers() {     return db.users.select(u => u); } 

i can retrieve data while assigning datasource datagridview throwing below error:

data binding directly store query (dbset, dbquery, dbsqlquery, dbrawsqlquery) not supported. instead populate dbset data, example calling load on dbset, , bind local data. wpf bind dbset.local. winforms bind dbset.local.tobindinglist(). asp.net webforms can bind result of calling tolist() on query or use model binding, more information see http://go.microsoft.com/fwlink/?linkid=389592.

can me error? how can assign retrieved data source datagridview listview?

call tolist() method. this:

public object getusers() {    return db.users.tolist(); } 

also can use asqueryable() this: (returning iqueryable<t> defer execution of query until results used.)

public iqueryable<user> getusers() {    return db.users.asqueryable(); } 

read post may useful: why use asqueryable() instead of list()


Comments