marten
marten copied to clipboard
WriteArray method doesn't honor multi-tenancy
- Setup the Marten document store with
_.Policies.AllDocumentsAreMultiTenanted();
- Store several documents with a specific tenantId.
- In the aspnet core web api action open the query session with that tenantId and use WriteArray() method like this:
app.MapGet("/{tenantId}/product", (string tenantId, [FromServices] IDocumentStore store, HttpContext context) =>
store.QuerySession(tenantId).Query<ProductListProduct>().Take(10).WriteArray(context)
);
The query generated looks like this:
select d.data from public.mt_doc_productlistproduct as d where d.tenant_id = :tenantid LIMIT :p1
tenantid:
p1: 10
As a result the empty array is returned. Note the empty tenantId.
- If instead of
WriteArray()
to useToList()
the query generated as this
select d.data from public.mt_doc_productlistproduct as d where d.tenant_id = :tenantid LIMIT :p1
tenantid: 5c3d2c5c71796847c037c41b
p1: 10
And the 10 documents array is returned.