当我尝试运行这个程序时,出现了一个错误:
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 不识别方法 '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]]])', 而且这个方法不能被转换成一个存储表达式。
我不认为在这里将c.CorporationId强制转换为可空guid是有效的,因为 c.CorporationId 是一个可空 guid,但是p.corporationid只是一个普通的 guid。
有什么建议吗?
c.CorporationId equals p.CorporationId
或者c.CorporationId.GetValueOrDefault() equals p.CorporationId
- AD.Net