我得到一個錯誤,當這種嘗試運行:如何將一個可空的guid與一個linq查詢中的guid進行比較?
Nullable<Guid> ng = corpid;
var qry1 = from c in entities.Transactions
join p in entities.Products on c.CorporationId equals (Nullable<Guid>) p.CorporationId
where c.Branch == br &&
c.AccountNumber == accountnumber &&
c.CorporationId == ng
orderby c.TransactionDate descending
select new
{
Date = c.TransactionDate,
RefNo = c.ReferenceNumber,
DlvryAcct = c.DeliveryAccount,
Desc = p.Description,
GasQty = c.GasQuantity,
Total = c.Amount,
Balance = c.Balance
};
這是消息:
LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1[f__AnonymousType1`7[System.Nullable`1[System.DateTime], System.String,System.String,System.String,System.Nullable`1[System.Decimal], System.Nullable`1[System.Decimal],System.Nullable`1[System.Decimal]]] Reverse[f__AnonymousType1`7](System.Linq.IQueryable`1[f__AnonymousType1`7[System.Nullable`1[System.DateTime], System.String,System.String,System.String,System.Nullable`1[System.Decimal], System.Nullable`1[System.Decimal],System.Nullable`1[System.Decimal]]])' method, and this method cannot be translated into a store expression.
我不認爲中投可空GUID是在這裏工作。 c.CorporationId
是一個可以爲空的指導,但p.corporationid
只是一個指導。
有什麼建議嗎?
你能這樣做嗎? 在實體中連接p。在c.CorporationId上的產品等於p.CorporationId == null ?? EMPTY_GUID:p.CorporationId –
如果您簡單地比較指令 'c.CorporationId等於p.CorporationId'或'c.CorporationId.GetValueOrDefault()等於p.CorporationId' –