-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Every Call To Load Method Add (Merge) Returned Entities To (With) Previous Record Sets #20510
Comments
@hamiddd1980 The purpose of In general, if there are two different units-of-work going on, which seems likely from your description, then a different context instance should be used for both. |
Hello.I was very thankful you are considering my problem.
My questions are : 3-If the mentioned code is not sensible , What's the best solution (Pattern) you suggest to Load and Track data from Db Server according to search phrase entered by user in Desktop apps: |
@hamiddd1980 Typically it would be unusual to filter by continually loading a new filtered collection from the database every time the filter string changes. Instead, it's more typical in this kind of dynamic scenario to load the data into the client and then filter there--for example, see the documentation on collection views. Beyond this, we are looking into patterns and guidance for data binding--this is tracked by #19588. Some of this guidance will be similar to the docs we have for data binding with EF6, since EF Core behaves in a similar manner. |
Hello.
In EF CORE , after calling
Load
method on a DbSet twice (or more) with Different conditions using WHERE clause and then use Local and ToObservableCollection respectively, the Results of first query (with its defined WHERE Condition) is Added to results of second query .In the other words , the second result set doesn't satisfy it's WHERE condition and contains merged results of first query and second query.
With mentioned conditions , the only solution to to use LOAD , LOCAL and ToObservableCollection with different WHERE clauses (for example FILTERINF data) is Disposing and Recreating of DbContext class.
It is noteworthy ,this behavior of LOAD method is different from ToList method .every time we call ToList method on DbSet , the previous Result sets are cleared and a new Result sets according to defined condition is created.
I want to know is it possible to change the function of LOAD method so that it fills the DbContext based on defined condition and doesn't merge different Result sets?(I mean every call to LOAD clears internal used LIST without need to Dispose and Recreation of DbContext-a behavior like ToList method).
Thank You.
Steps to reproduce
1-Define an Entity (here Country Class with NAME property)
2-Define a DbContext Derived Class (here CountryDbContext ) with Countries of Type DbSet
3-Instansiate our CountryDbContext in Window Constructor
4-Define 2 methods to retrieve Records with different conditions using WHERE clause(for example one that get countries start with F(France) and the other one load countries that start with E(like England)
5-call above defined methods.
6-results of second method (countries start with E) contains France and England.
Let suppose we have a DbContext class named CountryDbContext with a DbSet which represents different Countries:
1-Defining our Country Class
2-Defining a DbContext class:
3-Creating CountryDbContext instance and populate it with sample data (for example in window Loaded event):
4-a method to retrieve Countries that start with "F"
5-a method to retrieve Countries that start with "E"
6-now call above methos separately:
GetCountriesStartWithF():
Result = "France"
GetCountriesStartWithE()
Result= "France" and "England"
Further technical details
EF Core version: 5.0.0-preview.2.20120.8
Database provider: (Microsoft.EntityFrameworkCore.Sqlite)
Target framework: (.NET Core 3.0)
Operating system: Windows !0
IDE: Visual Studio 2019 16.6 Preview 2
The text was updated successfully, but these errors were encountered: