This is a migrated thread and some comments may be shown as answers.

Underscore is a wildcard when searching a varchar(MAX) field

1 Answer 59 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Russell
Top achievements
Rank 1
Russell asked on 17 Jul 2014, 12:59 AM
If you have a string like "A-B" in a varchar(MAX) field and you search for "A_B" DataAccess will return "A-B" from the database.

To reproduce I created a table called Tests with a varchar(MAX) field called Str.

I added 2 test records.  "A" and "A-B"

I created a new Entities Model with the Tests Table and ran the following code.

Dim SearchStr As String = "A_B"
Dim EM As New EntitiesModel
Dim Obj As Test = (From e In EM.Tests Where e.Str = SearchStr  Select e).FirstOrDefault

Obj.Str returns "A-B" from the Tests Table

If you set SearchStr to "_" it will return "A" from the Tests Table

1 Answer, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 17 Jul 2014, 09:15 AM
Hi Russel,

yes, this seems to be a glitch. With MSSQL 2000, varchar(max) columns could not be sorted or compared except for LIKE and IS NULL. Later versions seem to have lifted this restriction, but our default converter initialization was not changed accordingly. I will mark this as a bug.
Workaround: Please specify the converter to be used for varchar(max) columns as VariableLengthAnsiStringConverter; and for nvarchar(max) use VariableLengthStringConverter. You can do that most efficiently either in the fluent mapping code by specifying
.WithConverter("VariableLengthAnsiStringConverter")
or by using the .rlinq editor (Model Operations-> Select Members, Column, SqlType varchar(max) -> Operations : Change Converter).

Please excuse the inconvenience caused by this.

Regards,
Thomas
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
General Discussions
Asked by
Russell
Top achievements
Rank 1
Answers by
Thomas
Telerik team
Share this question
or