internal class Program
    private static void Main(string[] args)
        var dc = new DomainConfiguration("sqlserver", "Data Source=.; Initial Catalog=DO40-Tests; Integrated Security=True;");


        dc.UpgradeMode = DomainUpgradeMode.Recreate;

        using (var d = Domain.Build(dc))
            using (var s = d.OpenSession())
            using (s.Activate())
            using (var t = s.OpenTransaction())
                new TestEntity(s) { String = "[test]"};
                new TestEntity(s) { String = "test"};


            using (var s= d.OpenSession())
            using (s.Activate())
            using (var t = s.OpenTransaction())
                Assert.AreEqual(1, Query.All<TestEntity>().Count(e => e.String.Contains("[test]")));


public class TestEntity : Entity
    /// <summary>Initializes a new instance of this class.</summary>
    /// <param name="session">The session.</param>
    public TestEntity(Session session) : base(session)

    [Field(Nullable = false)]
    public int Id { get; private set; }

    public string String { get; set; }

SQL query

SELECT COUNT_BIG(*) AS [c01umn] FROM [dbo].[TestEntity] [a] 
WHERE ([a].[String] LIKE N'%[test]%');

I assume, we need something like this

SELECT COUNT_BIG(*) AS [c01umn] FROM [dbo].[TestEntity] [a] 
WHERE ([a].[String] LIKE N'%^[test]%' ESCAPE N'^');

asked Jun 09 at 08:00

Gushchin%20Anton's gravatar image

Gushchin Anton

One Answer:

Hello Anton,

There is an extension for string values called Like(...), declared in Xtensive.Core.StringExtensions class. It allows to specify escape character.

answered Jun 13 at 00:11

Alexey%20Kulakov's gravatar image

Alexey Kulakov

It's good, but not sufficient)

I expect Contains would work like C# method, and it do so for other inputs

For example, if I use linq construction like this 'e.String.Contains ("%test%")', DO translate expression into 'WHERE ([a].[String] LIKE N'%^%test^%%' ESCAPE N '^')'

i.e. DO already escaping some characters, but not '['

That why I assume this behavior as a bug

(Jun 13 at 03:15) Gushchin Anton Gushchin%20Anton's gravatar image

DO escapes the '%' because this is one of general special characters. These characters should be escaped anyway. But the '[' is from MS SQL Server dialect only so it is not escaped.

Unfortunately, there is no way to get such behavior you want for now because Api for method compilers is not storage-dependent, they are commonly used by all providers

(Jun 14 at 06:50) Alexey Kulakov Alexey%20Kulakov's gravatar image

Ok, and yet DO could add escaping symbol anyway for '['

In MS SQL we would get desirable behavior

And in PostgreSQL, for example, nothing changes

This query result

SELECT * FROM [Test] WHERE Name LIKE '^[test^]' ESCAPE '^'

Equal to this

SELECT * FROM [Test] WHERE Name LIKE '[test]'

(Jun 15 at 01:48) Gushchin Anton Gushchin%20Anton's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA