1

I want to compare two lists extracted from two different tables

var maListe = db.exclure.Where(w => w.type.Contains("Object class"))
                        .GroupBy(g => new {libelle = g.libelle,})
                        .Select(s => new {libellex = s.Key.libelle}).ToList();

var myList = db.Full.Where(c => c.date_reception > new DateTime(2015, 02, 02))
               .Where (c => !maListe.Any(c2 => c2.libellex.Contains(c.mc_object_class)))
               //.Where (p => p.mc_object_class.CompareTo("NULL")<0)
                 .GroupBy(f => new
                    {
                        object_class = f.mc_object_class,
                    })
                 .Select(g => new 
                    { 
                        object_classx = g.Key.object_class, 
                        countx = g.Count() 
                    })
                 .Take(10)
                 .OrderByDescending(o => o.countx)
                 .ToList();

I'm looking for elements that exist in myList and not in maListe, while running the code above I get the following error:

Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context.'

1 Answer 1

1

You should materialize your collection, something like:

var maListe = db.exclure.Where(w => w.type.Contains("Object class"))
                    .GroupBy(g => new {libelle = g.libelle,})
                    .Select(s => new {libellex = s.Key.libelle}).ToList();

var myList = db.Full.Where(c => c.date_reception > new DateTime(2015, 02, 02))
           .AsEnumerable() // database query ends here
           .Where (c => !maListe.Any(c2 => c2.libellex.Contains(c.mc_object_class)))
           //.Where (p => p.mc_object_class.CompareTo("NULL")<0)
             .GroupBy(f => new
                {
                    object_class = f.mc_object_class,
                })
             .Select(g => new 
                { 
                    object_classx = g.Key.object_class, 
                    countx = g.Count() 
                })
             .Take(10)
             .OrderByDescending(o => o.countx)
             .ToList();

If you will have time, please, take a look to msdn

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.