Does marten support set operations? (Union etc) #1763
-
Tried using Union method but it didn't work. public class MyClass
{
public Guid Id { get; set; }
public string SomeInfo { get; set; }
}
public static async Task Main()
{
CreateDatabaseIfNotExists(GetConnectionString()); // CREATE DATABASE ...
var store = DocumentStore.For(GetConnectionString());
using (var session = store.OpenSession())
{
var myClass1 = new MyClass {SomeInfo = "some info 1"};
var myClass2 = new MyClass {SomeInfo = "some info 2"};
session.Store(myClass1);
session.Store(myClass2);
await session.SaveChangesAsync();
}
using (var session = store.OpenSession())
{
var query = GetQueryable(session);
var query1 = query.Where(obj => obj.SomeInfo == "some info 1");
var query2 = query.Where(obj => obj.SomeInfo == "some info 2");
var union = query1.Union(query2);
var areQueriesCountEqual = query.Count() == union.Count(); // false
var query1Guids = query1.Select(obj => obj.Id).ToArray();
var unionGuids = union.Select(obj => obj.Id).ToArray();
var areGuidsEqual = query1Guids.SequenceEqual(unionGuids); // true
var query2HasElements = query2.Any(); // true
}
}
private static IQueryable<MyClass> GetQueryable(IQuerySession session)
{
return session.Query<MyClass>();
} |
Beta Was this translation helpful? Give feedback.
Answered by
jeremydmiller
Mar 11, 2021
Replies: 1 comment
-
@Nadare2012 No, Marten does not support And the batched queries will be more efficient in v4 FWIW. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Abdragiz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Nadare2012 No, Marten does not support
Union()
queries. To be honest, I didn't realize that was a thing in Linq. The functional equivalent in Marten would be to use the batched query functionality: https://martendb.io/documentation/documents/querying/batched_queries/And the batched queries will be more efficient in v4 FWIW.