When using LINQ to an entity, string comparisons ignore spaces.
My table has a nchar (10) column, so any stored data, if it's not 10 characters, will fill the rest with blank spaces. Below I compare "ncharTextColumn" with the string "Four" . And even if ncharText is equal to "Four " this will lead to a match, and the variable "result" will contain 1 entry
TestEntities1 entity = new TestEntities1(); var result = entity.Table_1.Where(e => e.ncharText == "Four");
Is there an explanation for this and a way around this, or will I have to call ToList for my request before any comparisons like this.
var newList = result.ToList().Where(e => e.ncharText == "Four");
This code now correctly returns 0 records, since it takes into account spaces. However, accessing the list before comparing can lead to loading a large amount of memory into memory, which will not be used in the end.
c # linq-to-entities entity-framework
user2945722
source share