Kann nicht implizit konvertiert Typ 'System.Sammlungen.Generisches.Liste<AnonymousType#1>' zu 'System.Linq -.IQueryable<AnonymousType#2>'

Diese Abfrage kompiliert wird ohne Fehler:

            var _entityList = context.customer

                .Join(context.applications,
                cust => cust.cust_id,
                app => app.cust_id,
                (cust, app) => new { customer = cust, application = app })

                .Join(context.advices,
                cust => cust.application.app_id,
                sa => sa.app_id,
                (cust, sa) => new { customer = cust, advice = sa })

                .GroupBy(g => new { g.customer.customer.cust_id, g.customer.customer.cust_code, g.customer.customer.cust_name })
                .Select(g => new { cust_id = g.Key.cust_id, cust_code = g.Key.cust_code, cust_name = g.Key.cust_name })
                .ToList();

Wird, während Sie eine bedingte where-Klausel für die obige Abfrage gibt compile-Zeit-Typ-Konvertierungsfehler:

            var _entityList = context.customer

                .Join(context.applications,
                cust => cust.cust_id,
                app => app.cust_id,
                (cust, app) => new { customer = cust, application = app })

                .Join(context.advices,
                cust => cust.application.app_id,
                sa => sa.app_id,
                (cust, sa) => new { customer = cust, advice = sa });

            if (custcode != null && custcode != "")
                _entityList = _entityList.Where(e => e.customer.customer.cust_code == custcode);

            _entityList = _entityList
                .GroupBy(g => new { g.customer.customer.cust_id, g.customer.customer.cust_code, g.customer.customer.cust_name })
                .Select(g => new { cust_id = g.Key.cust_id, cust_code = g.Key.cust_code, cust_name = g.Key.cust_name })
                .ToList(); //error on this line

Kann nicht implizit konvertiert Art System.Collections.Generic.List<AnonymousType#1> zu System.Linq.IQueryable<AnonymousType#2>

Was bin ich?

  • Sind Sie sicher, dass e.Kunden.Kunden.cust_code und custcode sind die normalen strings?
  • _entityListis vom Typ IQueryable und Sie versuchen, zuweisen in der Liste?
  • Ich schlage vor, Sie erstellen eine Typ-Klasse und verwendet ihn, Ihr wählt
  • bis letzten _entityList = _entityList, _entityList ist IQueryable<Type1>. Mit Ihrem letzten linq erstellen Sie eine neue Art , erstellen Sie eine Liste aus und versuchen Sie es zu assing das Ergebnis IQueryable<Type1>. (Wie IQueryable<Type1> = List<Type2>)
  • ja, beide sind normale Zeichenketten. auch wenn ich die bedingte auskommentieren, wo, noch gibt Kompilierungsfehler.
  • sorry, habe ich nicht bekommen, Sie @ " ... erstellen Sie eine Liste aus und versuchen Sie zu ordnen ...."
  • siehe meine Antwort...

InformationsquelleAutor Khadim Ali | 2013-08-15
Schreibe einen Kommentar