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

Chaining SearchChildren? #24

Open
LordMike opened this issue Apr 20, 2018 · 2 comments
Open

Chaining SearchChildren? #24

LordMike opened this issue Apr 20, 2018 · 2 comments

Comments

@LordMike
Copy link

Hi,

Just discovered this library. I was way down a path of Expression magic when a colleague pointed me here. So far, this is awesome :).

I'm now trying to find all Persons in my DB (EF Core), where a certain relationship has a number of conditions met. My relationship is an EAV model, so the relation stores many records in the form of "Name=Value" pairs.

I tried this.

db.Persons.SearchChildren(x => x.EAV)
  .With(x=>x.Name).EqualTo("SomeProperty")
  .With(x=>x.Value).Contains("a", "b");

Which works. But chaining it like this, does not. It simply replaces the final query with just the last SearchChildren call:

db.Persons.SearchChildren(x => x.EAV)
  .With(x=>x.Name).EqualTo("SomeProperty")
  .With(x=>x.Value).Contains("a", "b")
.SearchChildren(x => x.EAV)
  .With(x=>x.Name).EqualTo("OtherProperty")
  .With(x=>x.Value).Contains("b", "c");

Should this be possible, if so, what am I missing?

@ninjanye
Copy link
Owner

Hi @LordMike

Thanks for getting in touch. This should indeed be possible, in the interim, you could .ToList() the first part an then perform the second, however this could be heavy on memory if you have a lot of records (which I'm guessing you being EAV)

If you fancy it, I'd be happy to accept a PR that adresses this, otherwise I'll try and look into this, this week.

Thanks again

@LordMike
Copy link
Author

I'm unsure where I would start. I could only observe that the last SearchChildren seemed to take precedence.

I've worked around the issue by performing a number of regular Search'es on the EAV data, extracting unique ID references, and then searching in my source data as usual but filtering to the list of ID's.. I only have a few thousand records (tens of thousands EAV records), so this works.

I'd prefer a proper SearchChildren though :).

Also. I've added your library to https://github.com/thangchung/awesome-dotnet-core

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

2 participants