You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to somehow filter or sort data by related documents? If I have aggregates/documents Order, Customer and Producst, in SQL I can write something like this:
Filtering
SELECT o.*FROM Orders o
INNER JOIN Customers c onc.Id=o.CustomerIdINNER JOIN Products p onp.Id=o.ProductIdWHEREc.CityLIKE'P%'ANDp.Price>100
Sorting
SELECT*FROM Orders o
INNER JOIN Customers c onc.Id=o.CustomerIdINNER JOIN Products p onp.Id=o.ProductIdORDER BYc.City, p.Price
Sometimes I need combination of both. And I use sorting for paging. So I have a lot of data, so I sort them and then get only 10th page of 20 records.
I cannot see how to do the same with Marten. For the first sample with filter I can separately load filtered Customers, filtered Products, get their IDs and then filter Order by this IDs. If there are many records in DB (milions or more) for each document that satisfy the filter condition this meens I have to load all this IDs into memory. Then for combination of these conditions there can be only few records or none. So this is not a good way for me.
For the sorting example it is much more complicated when combined with paging.
It would be nice when there is some concept like navigation properties in Entity Framework. For the first example I would write something like this
This would be great and a much appreciated qualify of life feature.
Also an overload for include to allow explicit including of related documents instead of having to output to a dictionary would be a great quality of life feature as well.
CREATETABLEtable1 (
id SERIALPRIMARY KEY,
data JSONB
);
CREATETABLEtable2 (
id SERIALPRIMARY KEY,
other_data VARCHAR(50)
);
-- Insert some sample dataINSERT INTO table1 (data) VALUES ('{"foreign_key": 1}');
INSERT INTO table2 (other_data) VALUES ('Data related to foreign key 1');
-- Join the tables using the foreign key stored in the JSONB fieldSELECT*FROM table1 t1
JOIN table2 t2 ONt1.data->>'foreign_key'::INTEGER=t2.id;
Is it possible to somehow filter or sort data by related documents? If I have aggregates/documents
Order
,Customer
andProducst
, in SQL I can write something like this:Filtering
Sorting
Sometimes I need combination of both. And I use sorting for paging. So I have a lot of data, so I sort them and then get only 10th page of 20 records.
I cannot see how to do the same with Marten. For the first sample with filter I can separately load filtered Customers, filtered Products, get their IDs and then filter Order by this IDs. If there are many records in DB (milions or more) for each document that satisfy the filter condition this meens I have to load all this IDs into memory. Then for combination of these conditions there can be only few records or none. So this is not a good way for me.
For the sorting example it is much more complicated when combined with paging.
It would be nice when there is some concept like navigation properties in Entity Framework. For the first example I would write something like this
"Navigation property" can be defined like foreign keys as attribute
or maybe to reference FK
or as configuration
The text was updated successfully, but these errors were encountered: