dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.81k stars 3.2k forks source link

Consider IListSource on DbSet/Query #1431

Closed rowanmiller closed 9 years ago

rowanmiller commented 9 years ago

In EF6 we implemented IListSource to throw and point folks to the right way to data bind. We should consider doing this again.

smitpatel commented 9 years ago

@rowanmiller - Can you suggest exception message for this?

bricelam commented 9 years ago

Eww... another reason to cross-compile to net45

bricelam commented 9 years ago

@smitpatel Here's what we had in EF6:

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(). For ASP.NET WebForms you can bind to the result of calling ToList() on the query or use Model Binding, for more information see http://go.microsoft.com/fwlink/?LinkId=389592.

It threw NotSupportedException.

divega commented 9 years ago

Caveat: There is no DbSet.Local in EF7, at least not yet. Without it databinding is mostly manual, e.g. you can do .ToList() and then somehow make sure any items added or removed are added and removed on the context as well.

divega commented 9 years ago

Moreover, without DbSet.Local the value of throwing an exception here is:

rowanmiller commented 9 years ago

Proposed message:

Data binding directly to a store query is not supported. Instead materialize the results into a collection, by calling a method such as ToList() or ToArray(), and bind to the collection. This should be done to avoid sending a query to the database each time the databound control iterates the data.

Obviously we can add more info when we improve our databinding story (i.e. implement .Local).

DamirLisak commented 1 year ago

@ajcvickers : What does the label "type-unknown" mean? Will this be implemented that WPF-Controls can bind to a DBSet? We run to this issue because we are porting from 4.8 to core 7 and we have a lot of scenarios where we directly query the database without caching it to a temporary list.

ajcvickers commented 1 year ago

@DamirLisak No, this is by-design. Binding directly to the DbSet is a pit-of-failure because it causes a database query every time the set is enumerated. See Getting Started with WPF.