将utcnow
转换为本地时间时,会显示类似
“ LINQ to Entities无法识别方法'System.DateTime ToLocalTime()'方法,并且该方法无法转换为 存储表达式。”
我使用的是 SQL Server 2014 ,而不是 mango db 。当我在查询之外使用函数UTCtoLocal
时,它将起作用。但是我需要在 linq查询中使用它来加快执行速度。还有其他方法可以做到这一点。
group new
{
Id = ord.Id,
ShipmentInfoId = shipment.Id,
PartnerName = partner.Name,
PartNumber = ordItem.SellerProductID,
OrderNumber = ord.UniqueOrderID,
PartCount = shipment.PartCount,
DeliveryDate = ord.DeliveryDate,
IsSentInvoice = shipment.IsSentInvoice != null ? shipment.IsSentInvoice : false,
IsSentASN = shipment.IsSentASN != null ? shipment.IsSentASN : false,
ShippingPartCount = 0,
IsManualEntered = ord.IsManualEntered,
LastGeneratedInvoiceDate = shipment.LastGeneratedInvoiceDate.Value.UtcToLocal(),
LastGeneratedASNDate = shipment.LastGeneratedASNDate.Value.UtcToLocal(),
答案 0 :(得分:0)
在这里通过与DateTimeKind.Utc和ToLocalTime()一起解决问题
var dt = new DateTime(2010, 1, 1, 1, 1, 1, DateTimeKind.Utc);
string s = dt.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss \"GMT\"zzz");
Console.WriteLine(s);