SearchExtensions icon indicating copy to clipboard operation
SearchExtensions copied to clipboard

Chaining SearchChildren?

Open LordMike opened this issue 7 years ago • 2 comments

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?

LordMike avatar Apr 20 '18 22:04 LordMike

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

ninjanye avatar Apr 24 '18 12:04 ninjanye

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

LordMike avatar Apr 24 '18 12:04 LordMike