尝试运行时出现错误:
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
是一个可为 null 的 guid,而 p.corporationid
只是一个 guid。
有什么建议吗?
最佳答案
您是否尝试过放弃转换并将 c.CorporationId
等同于 ng.Value
?:
Nullable<Guid> ng = corpid;
var qry1 = from c in entities.Transactions
join p in entities.Products on c.CorporationId equals p.CorporationId
where c.Branch == br &&
c.AccountNumber == accountnumber &&
c.CorporationId == ng.Value
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
};
关于c# - 如何在 linq 查询中将可为空的 guid 与 guid 进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13996433/