I have this query :
select '[' + p.Firstname + ']' from Person p
where p.Firstname = 'Johanne'
In the table, I have multiple personne who have this firstname, and some have a trailing space on the value (bad insertion of the values, it will be corrected).
Why then does this query bring me this result (I inserted the brackets to visualize the spaces) :
[Johanne]
[Johanne ]
[Johanne ]
[Johanne]
Is this a configuration thing ? The real query comes from entity framework 6, but this example does it also. How can I prevent it ?
Thanks !
Edit: I could make it work using EF6 and the System.Data.Entity.SqlServer.SqlFunctions.DataLength
method like this:
ctx.Person.FirstOrDefault(p => p.FirstName == "Johanne" && SqlFunctions.DataLength(p.FirstName) == "Johanne".Length);