我得到一个错误,当这种尝试运行:如何将一个可空的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' –