我有一张名为 CateringPurchaseOrder 的桌子。该表包含一个名为“PONO”的列。该列不止一次包含相同的值。我想根据“pono”列中的唯一值检索记录。
例子:
pono column1
1 value1
1 value2
2 value3
2 value4
输出:
pono coulm1
1 value1
2 value3
我尝试过使用以下代码:
IEnumerable<CateringPurchaseOrder> order = entites.CateringPurchaseOrders.Distinct<CateringPurchaseOrder>(new CateringPorderComparer());
public class CateringPorderComparer : IEqualityComparer<CateringPurchaseOrder>
{
bool IEqualityComparer<CateringPurchaseOrder>.Equals(CateringPurchaseOrder p1, CateringPurchaseOrder p2)
{
return p1.P_O_No == p2.P_O_No;
}
int IEqualityComparer<CateringPurchaseOrder>.GetHashCode(CateringPurchaseOrder obj)
{
return obj.P_O_No.GetHashCode();
}
}
我收到以下错误:
LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1[MilitarymessModel.CateringPurchaseOrder] Distinct[CateringPurchaseOrder](System.Linq.IQueryable`1[MilitarymessModel.CateringPurchaseOrder], System.Collections.Generic.IEqualityComparer`1[MilitarymessModel.CateringPurchaseOrder])' method, and this method cannot be translated into a store expression.
你有解决这个问题的方法吗?