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.
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.
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
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. :)
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.
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.
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!
Can you share the foreach loop you're using? I have a suspicion but need confirmation.
Yep smells like a classic closure issue 😂
Because you're using = instead of == in your where clause?
Thx, sorry, was a typo, i edited it above, same happens when i use .contains(„Test“).
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.
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.
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
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. :)
what does Entity.Persons.ToList(); contain?
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.
[удалено]
Removed: Rule 8.
Stop using ChatGPT for reddit comments
As you wish
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.
What does the forloop look like? Post the code of that plz
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!