Skip to content

Instantly share code, notes, and snippets.

@CodingGorilla
Created September 17, 2018 20:51
Show Gist options
  • Save CodingGorilla/93a5e8204c9dd00b047e18a986fdfaae to your computer and use it in GitHub Desktop.
Save CodingGorilla/93a5e8204c9dd00b047e18a986fdfaae to your computer and use it in GitHub Desktop.
Marten Compiled Query error
class Program
{
private static DocumentStore _documentStore;
static void Main(string[] args)
{
var connectionString =
$"SCRUBBED";
_documentStore = DocumentStore.For(_ =>
{
_.Connection(connectionString);
});
var id3 = Guid.NewGuid();
using(var session = _documentStore.OpenSession())
{
session.Store(new TestClass {TestString = "test1"});
session.Store(new TestClass {TestString = "test2"});
session.Store(new TestClass {TestString = "test3", Id = id3});
session.SaveChanges();
}
using(var session = _documentStore.OpenSession())
{
var result = session.Query(new CompiledQuery2 { IdValue = id3 });
Console.WriteLine(result);
result = session.Query(new CompiledQuery1 { StringValue = "test2" });
Console.WriteLine(result);
}
}
}
public class CompiledQuery1 : ICompiledQuery<TestClass, bool>
{
public string StringValue { get; set; }
public Expression<Func<IQueryable<TestClass>, bool>> QueryIs()
{
return q => q.Any(x => x.TestString.EqualsIgnoreCase(StringValue));
}
}
public class CompiledQuery2 : ICompiledQuery<TestClass, bool>
{
public Guid IdValue { get; set; }
public Expression<Func<IQueryable<TestClass>, bool>> QueryIs()
{
return q => q.Any(x => x.Id == IdValue);
}
}
public class TestClass
{
public Guid Id { get; set; }
public string TestString { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment