我正在尝试运行下面的linq语句。我收到以下错误消息:
LINQ to Entities不支持指定的类型成员'CustomerID'。仅支持初始化程序,实体成员和实体导航属性。
我介入了代码,当我接受查询并尝试使用“ToList()”进行转换时,它就会发生。
有什么想法吗?我将如何重写此查询,以便LINQ to Entities停止抱怨。
史蒂夫
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
});
答案 0 :(得分:2)
我认为问题在于您无法加入匿名类型的集合。
将PricingId
属性移至后来的let
子句,并直接加入Customers
。