简体   繁体   中英

Linq query returning the same result over and over

I have the following linq query returning the same result over and over even though the "cptAuxList" variable is changing:

    static Func<VBANKDataContext, decimal, IQueryable<SldValue>> GetSldAll = CompiledQuery.Compile((VBANKDataContext VB, decimal date) =>
        (from cpt in VB.AGSFCA
         where cptAuxList.Contains(cpt.CPTAUX)
         && cpt.FINPRD == date
         select new SldValue() {
            AUX = cpt.CPTAUX,
            SNS = cpt.SNSSLD,
            SLD = cpt.SLDCPT
         })
    );

The list is being resetted every 2000 unique values stored:

    static void AddIfNotContains(string CPTAUX)
    {
        string cptAuxToAdd = CPTAUX.Trim();

        if (!cptAuxList.Contains(cptAuxToAdd) && !cptAuxDone.Contains(cptAuxToAdd))
        {
            cptAuxList.Add(cptAuxToAdd);

            if (cptAuxList.Count >= 2000)
            {
                VBANKDataContext VB = new VBANKDataContext();
                List<SoldeValue> auxToSldTemp = GetSoldeAll(VB, DateDernArt).ToList();
                auxToSld.AddRange(auxToSldTemp);

                cptAuxDone.AddRange(cptAuxList);
                cptAuxList.Clear();
            }
        }
    }

The variable is declared this way:

 static List<string> cptAuxList = new List<string>();

What seems to happen is that the first time I call "GetSldAll", it works as expected, and then the next calls, it returns the same result as the first one like if the values contained in the cptAuxList list doesn't change.

It seems the only variable you defined is the date. Everything else is taken in the moment it is compiled. That's the whole point of compiling it: reuse.

If you need cptAuxList to be a variable as well, you need to define it as one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM