在实体框架中不能使用sql函数吗?

时间:2018-06-08 11:38:09

标签: c# entity-framework linq datetime

当我尝试使用sql函数从日期获取月份并在linq中使用时。它不起作用。它显示异常,例如只能使用从linq到sql的实体框架

var Month = (SqlFunctions.DatePart("month", date));

using (var context = new BSoftWEDIIContext())
{
    var partSummaryForShipmentOrderData = from order in context.Order
        join orderItem in context.OrderItems on order.Id equals orderItem.OrderId
        join partner in context.Partners on order.PartnerID equals partner.Id
        join part in context.Parts on orderItem.SellerProductID equals part.Number
        join shipmentInfo in context.ShipmentInfo on order.Id equals shipmentInfo.OrderId
        join shippingPackageInfo in context.ShippingPackageInfos on shipmentInfo.Id equals shippingPackageInfo.ShipmentInfoID
        where                                                         
            (SqlFunctions.DatePart("month", shipmentInfo.DeliveryDate) == Month)
            && !order.IsDeleted && !partner.IsDeleted && !orderItem.IsDeleted && !part.IsDeleted
            && !shipmentInfo.IsDeleted && !shipmentInfo.IsDeleted
            && !shippingPackageInfo.IsDeleted
        group new
        {
            DeliveryDate = shipmentInfo.DeliveryDate,
            Quantity = shippingPackageInfo.Quantity,
            Partner = partner.Name,
        } by part.Number
}

0 个答案:

没有答案