Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"System.Data.SqlClient.SqlException: Syntax error near ... in the full-text search condition ..." when using special characters #4

Open
icnocop opened this issue Nov 3, 2016 · 3 comments

Comments

@icnocop
Copy link
Contributor

icnocop commented Nov 3, 2016

I expected to be able to perform a full text search using special characters.

Here is an example unit test that fails for each of these special characters, but there could be more.

        [TestMethod]
        public void Contains_UsingSpecialCharacters_Succeeds()
        {
            foreach (string specialCharacter in new[]
            {
                "\"",
                "'",
                ")",
                "(",
                "%"
            })
            {
                using (var db = new MyDbContext())
                {
                    db.Database.Log = Console.WriteLine;
                    var text = FullTextSearchModelUtil.Contains(specialCharacter);
                    var query = db.TestModel
                        .Where(c => c.Name.Contains(text))
                        .ToList();
                }
            }
        }

Any work-arounds or recommendations?

Thank you!

chsword added a commit that referenced this issue May 20, 2017
Add Test #4
@shyamal890
Copy link

If I enter a string like '[Something]'. I get an error saying

Syntax error near '[' in the full-text search condition '(~[something])

Same issue with a string containing commas

Syntax error near ',' in the full-text search condition '(KGBV,Vinchiya,Jasdan)

@icnocop @chsword were you able to find a workaround for this?

@chsword
Copy link
Member

chsword commented Oct 17, 2017

@shyamal890
'[Something]' do not work with contains(it do not work in the T-SQL also), I think in this case, maybe try freetext

@icnocop
Copy link
Contributor Author

icnocop commented Nov 25, 2019

I also found the same error with these special characters:
Underscore (_)
Tilde (~)
Caret Symbol (^)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants