Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement MTM relation without getting duplicate data on a Multi-Poco query? #718

Open
Tilation opened this issue Feb 8, 2024 · 0 comments

Comments

@Tilation
Copy link

Tilation commented Feb 8, 2024

I'm trying to get Many-To-Many related entities using the Multi-Poco query as such, but it returns duplicated data.

var sql = @"select m.*, q.*
from test.queue q
left join test._monitor_queue mq on q.id_queue = mq.id_queue
left join test.monitor m on m.id_monitor = mq.id_monitor
where m.id_monitor = 1;";

var result = db2.Query<Data.Monitor, Queue, Data.Monitor>((monitor, queue) => 
{
    if (monitor.Queues == null) monitor.Queues= new List<Queue>();
    monitor.Queues.Add(queue);
    return monitor;
}, sql).ToArray();

I expected the Func to run with the same monitor entity (as the sql query returns the queues for a single monitor) but it creates a new monitor for each queue.

Result:

Monitor Queue List
Monitor0 [Queue0]
Monitor1 [Queue1]

Expected Result:

Monitor Queue List
Monitor0 [Queue0, Queue1]

Is MTM supported by PetaPoco? How can I achieve my expected result?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant