Search code examples
c#data-bindingado.net

How many records are loaded into the BindingSource?


I've always worked with Linq and that's why I always brought only the necessary records for operation - obviously everything was hand-coded.

Now, I'm studying Data Binding because I understand that I can speed up the whole process a lot.

However, I have a question about the initial load of the BindingSource. I noticed that the sample codes always contain the .Load () command without specifying an initial filter.

Example:

dbContext ctx = new dbContex();
ctx.Table.Load(); <-- Here is my doubt
myBindingSource.DataSource = ctx.Table.Local.ToBindingList()

Let's assume that this table has 10,000 records. Will it load 10,000 records at once? Doesn't this type of operation make the load very slow and consume a lot of network bandwidth?


Solution

  • According to documentation

    One common way to do this is to write a LINQ query and then call ToList on it, only to immediately discard the created list. The Load extension method works just like ToList except that it avoids the creation of the list altogether.

    So, if you just call

    ctx.Table.Load()
    

    it will load all the data on that table.

    You can also query it before calling Load()

    context.Posts.Where(p => p.Tags.Contains("stackoverflow")).Load();