1 year ago

#296884

test-img

Dominique

Why seems "Extent.Skip(1).First()" not to work in a for-loop?

C# newbie question here.

In my database, I have a Load table, filled with a lot of entries.
I have done the following in the past and it was working fine:

var list_Loads = database.GetData<Load>().AsQueryable();
Load load_1 = list_Loads.First();
Load load_2 = list_Loads.Skip(1).First();
Load load_3 = list_Loads.Skip(1).First();
Load load_4 = list_Loads.Skip(1).First();
...

By "working fine" I mean that load_x is different for x being 1, 2, 3, 4, ...

Now I'm trying to do the following:

var list_Loads = database.GetData<Load>().AsQueryable();
Load load_1 = list_Loads.First();
...
database.SaveChanges();
for (int i=1; i<=99 ; i++)
{
    log.Debug($"Test number [{i}]");
    load_1 = list_Loads.Skip(1).First();
    ...
    database.SaveChanges();
}

What I now see, is that the first time the value of load_1 changes indeed, but next times (when for-loop index i increases), the value of load_1 stays the same (I can confirm that there are plenty of entries in list_Loads).

Does anybody know why and how I can solve this?

For your information, I already tried:

var load_i = list_Loads.Skip(1).First();

This did not help.

P.s. I have use Extent as a tag for this question, as list_Loads is an extent, according to the watch-window. I'd like to use the kind of expressions, like .Skip(1).First() but I don't know how this is called.

c#

for-loop

extent

0 Answers

Your Answer

Accepted video resources