Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Newbie to Linq
Message
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Titre:
Newbie to Linq
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01605340
Message ID:
01605340
Vues:
84
Hi all just playing around with LINQ and EF and need some help with what I think is a pretty simple query
int InvoiceAmount = 1000000;

var results =
                 from cl in Context.clients.ToList().Distinct()
                 from inv in cl.invoices.ToList().Where(x => x.invoiceamount >= InvoiceAmount)
                 where cl.id == inv.clientid
                 select cl;
clients and invoices are the two underlying tables and are joined on id->clientid fields, where one client has one or more invoices, in my attempt shown above I thought I would only get invoices ( invoices is a navigational property of client ) with a value >= InvoiceAmount but I get all that are linked to a client. I think it must be down to LINQ's deferred execution but don't know how to work around it except by filtering the invoice list again which is not ideal
int i = 0;
                foreach (client c in results)
                {
                     i++;
                     Console.WriteLine("Company: {0} (id: {1})", c.companyname, c.id);

                     foreach (invoice inv in c.invoices) // This is where I think the query selects all invoices related to the current client.
                     {
                         Console.WriteLine("\t Invoice reference: {0}", inv.invoicereference);
                         Console.WriteLine("\t\t Invoice date: {0}", inv.invoicedate.Value.ToString("dd/MM/yyyy"));
                         Console.WriteLine("\t\t Invoice amount: {0}", inv.invoiceamount.Value.ToString("C"));
                         Console.WriteLine("\t\t Charge type: {0}", inv.chargetypes.chargetypename);
                     }
Regards,
Peter J. Kane



Pete
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform