Skip to content
On this page

Mixing Raw SQL with Linq

Combine your Linq queries with raw SQL using the MatchesSql(sql) method like so:

cs
[Fact]
public void query_with_matches_sql()
{
    using var session = theStore.LightweightSession();
    var u = new User { FirstName = "Eric", LastName = "Smith" };
    session.Store(u);
    session.SaveChanges();

    var user = session.Query<User>().Where(x => x.MatchesSql("data->> 'FirstName' = ?", "Eric")).Single();
    user.LastName.ShouldBe("Smith");
    user.Id.ShouldBe(u.Id);
}

snippet source | anchor

Released under the MIT License.