Git Product home page Git Product logo

Comments (7)

yv989c avatar yv989c commented on July 1, 2024

Hi @Tyler-V ! Does this work? I'm away from my computer.

public async Task<List<Package>> GetPackagesAsync(List<int> list1, List<string> list2)
{
    return await _context.Package
        .Where(p =>
            _context.AsQueryableValues(list1).Contains(p.p1) &&
            _context.AsQueryableValues(list2, true).Contains(p.p2))
        .ToListAsync();
}

I believe your original query should behave the way your are asking (AND)... Are p.p1 and p.p2 nullable?

from blazartech.queryablevalues.

Tyler-V avatar Tyler-V commented on July 1, 2024

Hey @yv989c we tried that and it still pulls more records than necessary because the two lists are independent of each other

i.e.
In the database,
1 / ABC
1 / XYZ

List list1 = { 1 }
List list2 = { "ABC" }

We would want packages that only contain 1 and ABC, but this is pulling back 1 and XYZ as well,

We are using something like this now to get desirable results, not sure if there is a better way

        var packages = await _context.Package
            .Where(p => _context
                .AsQueryableValues(accumulations.Select(a => a.nm1), true)
                .Contains(p.p1 + "_" + p.p2))
            .ToListAsync();

[NotMapped] public string nm1 => p1 + "_" + p2;

from blazartech.queryablevalues.

yv989c avatar yv989c commented on July 1, 2024

Does either p.p1 or p.p2 allow nulls?

from blazartech.queryablevalues.

Tyler-V avatar Tyler-V commented on July 1, 2024

No nulls will exist in either set

from blazartech.queryablevalues.

yv989c avatar yv989c commented on July 1, 2024

I'm confused because of the word "set"... not sure if you are referring to the input list or your entity's properties. Would you please clarify? My question is about the two properties on your Package entity. Do you know if the underlying table allow nulls in those fields?

Also, does this give you a different result?

public async Task<List<Package>> GetPackagesAsync(List<int> list1, List<string> list2)
{
    return await _context.Package
        .Where(p =>
            _context.AsQueryableValues(list1).Where(i => i == p.p1).Any() &&
            _context.AsQueryableValues(list2, true).Where(i => i == p.p2).Any())
        .ToListAsync();
}

from blazartech.queryablevalues.

yv989c avatar yv989c commented on July 1, 2024

Hey @Tyler-V , do you have any news about this?

I wasn't able to reproduce your issue on my end. In my test your original query works as expected (get Package entities where p1 and p2 is present in both list1 and list2).

I'm wondering if the problem is related to:

  • Database null semantics
  • The size of your lists

Would you mind sharing the following?

  • Version of EF you are using
  • The approximate number of elements in each list
  • SQL generated by your original query
  • The SQL data type and nullability used by p1 and p2

Thanks.

from blazartech.queryablevalues.

yv989c avatar yv989c commented on July 1, 2024

Closing due to inactivity.

from blazartech.queryablevalues.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.