我收到以下錯誤查詢實體類型'的顯式建築是不允許
Explicit construction of entity type '...TableClassName' in query is not allowed.
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
這裏是我的代碼。
tgdd = new List<TableClassName>();
context.DeferredLoadingEnabled = false;
var t = context.TableClassName.Where(...)
.GroupBy(g => new { g.Date, g.UserID })
.Select(g => new TableClassName
{
PK = 1,
Date = Convert.ToDateTime(g.Key),
Counted = g.Sum(x => x.Counted),
Time = g.Sum(x => x.Time),
MaxHR = g.Max(x => x.MaxHR),
PeakCal = g.Max(x => x.PeakCal),
PowerIndex = (g.Sum(x => x.PowerIndex)),
Target = g.Max(x => x.Target),
RepTotal = g.Sum(x => x.RepTotal),
Lifted = g.Sum(x => x.Lifted),
UserID = Convert.ToInt64(g.Key)
}).ToList();
foreach (TableClassName r in t)
{
tgdd.Add(r);
}
我沒有語法錯誤。這是一個Web服務。調用它時我會遇到問題。
我如何能分開他們有什麼建議?我是LINQ的新手。 – Kukoy