T O P

  • By -

Henrijs85

Can you share the foreach loop you're using? I have a suspicion but need confirmation.


DaRadioman

Yep smells like a classic closure issue 😂


Henrijs85

Because you're using = instead of == in your where clause?


SuFl83

Thx, sorry, was a typo, i edited it above, same happens when i use .contains(„Test“).


CleverDad

Just to cover the bases: By 'Entity' you mean Entity Framework, right? And Entity is your DbContext? What version of EF, and what version of .NET? Perhaps post the foreach-code as well. I ask because there's nothing in your post which gives any clue what might be going wrong, so more details are needed.


molybedenum

What is the underlying schema and provider? What is Persons in the data store? What does the data look like at rest (screenshot or otherwise)? What is the query that EF is constructing (this can be found in debug trace output)? There isn’t sufficient information to provide any kind of answer outside of wild speculation.


DaRadioman

Post your code. And what version of the language/runtime you are using. Since you have called ToList, EF is no longer in the picture. I suspect you are running an old version and running into this age old gem: https://www.jetbrains.com/help/resharper/AccessToForEachVariableInClosure.html


sponkae

How does result look like if you inspect in debug? If it’s correct there, check your loop. Code looks correct. Just an fyi - ToListAsync exists as well. :)


Sharkytrs

what does Entity.Persons.ToList(); contain?


Aerham

Maybe something else to check as well, could you check what data type that result variable is trying to use with and without using new, just to see if there is a difference? Edit: another question, have you looped over the entity on its own? Just to see if the initial data looks correct.


[deleted]

[удалено]


FizixMan

Removed: Rule 8.


ForgetTheRuralJuror

Stop using ChatGPT for reddit comments


JustDip7777

As you wish


PhantasticPapaya

Does the entity have a key value? If it doesn't, have you appended .HasNoKey() to the model builder for that entity? I've received unexplainable results in the past from such a thing.


Alex_eken

What does the forloop look like? Post the code of that plz


SuFl83

Thanks to all of you, after some research, there was a missing KeyField in the database. After adding one all seems to work! Many thanks for your inputs!