I have encountered a problem that I can reproduce in a simple test app.
I get an exception "Specified method is not supported" when I try to drill down from an entity through a collection.
Here is my test setup:
Database contains 3 tables: Invoice, LineItem and PartNum.
LineItem has 2 foreign keys, referencing Invoice and PartNum.
In the following code snippet, Query 1 works, but Query 2 throws an exception. Please note that the queries are only
for this test - they are not intended to do anything in a real scenario.
Code: Select all
using (MySQL3.DataContext3 db = new MySQL3.DataContext3())
{
// Query 1: This works
MySQL3.Invoice invoice = (from i in db.Invoices
where i.LineItems.First().ItemQty != 0
select i).FirstOrDefault();
if (invoice != null)
DisplayMessage(invoice.InvoiceNum.ToString());
else
DisplayMessage("None found");
// Query 2: This throws exception "Specified method is not supported"
invoice = (from i in db.Invoices
where i.LineItems.First().PartNum != null
select i).FirstOrDefault();
if (invoice != null)
DisplayMessage(invoice.InvoiceNum.ToString());
else
DisplayMessage("None found");
}
Our application has lots of queries of this general form.
The same code works fine in MS Linq.
Am I missing something?
If more information is required, I can provide the test project and database (they are pretty small).