Reputation: 2515
I am trying to run the linq statement below. I am getting the following error message:
The specified type member 'CustomerID' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
I stepped through the code and it happens when I take query and attempt to convert using "ToList()".
Any ideas? How would I rewrite this query so that LINQ to Entities stops complaining.
Steve
var query = from l in db.QBPOLines
join t in db.tblJobTasks on l.POID equals t.PurchaseOrderID
join j in db.tblJobTasks on t.JobID equals j.JobID
join c in
(
from c in db.tblCustomers
select new
{
c.CustomerID,
PricingID = c.PricingID == null || c.PricingID == 0 ? 1 : c.PricingID
}
) on j.CustomerID equals c.CustomerID
join m in db.QBItemsPriceMaps on l.Item equals m.ItemName
join s in db.tblCustomerPricingSchemes on c.CustomerID equals s.CustomerID into g1
from s in g1.DefaultIfEmpty()
join p in db.tblPricingSchemes on l.LangPairs equals p.PSLangPairID into g2
from p in g2.DefaultIfEmpty()
where t.JobID == jobID
&& s.PSLangPairID == l.LangPairs
&& p.PSDescID == c.PricingID
select new
{
j.JobID,
l.Item,
l.LangPairs,
l.Qty,
Rate = s.PSLangPairID != null
? (m.CustomerPriceField == "PS_FZ50" ? s.PS_FZ50 :
m.CustomerPriceField == "PS_FZ75" ? s.PS_FZ75 :
m.CustomerPriceField == "PS_FZ85" ? s.PS_FZ85 :
m.CustomerPriceField == "PS_FZ95" ? s.PS_FZ95 : null)
: (m.CustomerPriceField == "PS_FZ50" ? p.PS_FZ50 :
m.CustomerPriceField == "PS_FZ75" ? p.PS_FZ75 :
m.CustomerPriceField == "PS_FZ85" ? p.PS_FZ85 :
m.CustomerPriceField == "PS_FZ95" ? p.PS_FZ95 : null)
};
List<tblJobManagementLineItem> list = query.ToList().ConvertAll(i => new tblJobManagementLineItem
{
JobID = i.JobID,
LineItemDescr = i.Item,
LanguagePairID = i.LangPairs,
SourceWordCount = (int)i.Qty,
QtyToInvoice = (int)i.Qty,
//item.JobInvoiceID <--- Implement later
Rate = i.Rate
});
Upvotes: 0
Views: 893
Reputation: 887195
I believe the problem is that you can't join on a collection of anonymous types.
Move the PricingId
property to a later let
clause and join directly to Customers
.
Upvotes: 2