bmanmike39
asked on
How would I write the following query in Linq?
How would I write this query in Linq to sql
Invoice IVN = eo.Invoices.ToList().Where(x => x.InvoiceNumber == s).First();
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What's wrong with what you have? Really, only the ToList could be taken out (or maybe moved to the end).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
You would need to put some sort of order by in, otherwise you would not reliably get the record you are expecting depending on how the SQL execution plan changes (unless invoicenumber is unique). The ToList() is not needed, since Invoices is already a collection.