【发布时间】:2012-04-23 16:18:14
【问题描述】:
我创建了一个 EF 4 和 C# 来获取一些数据。我正在使用 Linq。如下:
public List<object> GenerateCallTrackingReport(int startRowIndex, int maximumRows, int createdByID)
{
var query = from c in this.ObjectContext.CallLogs
select new
{
CallLogID = c.CallLogID,
DomainName = c.CallDomain.FullName,
CreatedByID = c.CreatedByID,
CreatedBy = c.CreatedByUser.FirstName + " " + c.CreatedByUser.LastAccessIPN,
CalledOn = c.CallDate,
IssueResolutionTime = c.IssueResolutionTime,
CallType = c.CallType.FullName,
CallDescription = c.CallDescription,
CustomerName = (c.CustomerID > 0 ? c.Customer.FirstName + " " + c.Customer.LastAccessIPN : c.TempCaller.FirstName + " " + c.TempCaller.LastName),
CustomerEmail = (c.CustomerID > 0 ? c.Customer.Email : string.Empty),
CustomerResponse = c.Response.FullName,
IsPending = c.IsPending,
NeedFurtherContact = c.NeedFurtherContact
};
if (createdByID > 0)
query = query.Where(c => c.CreatedByID == createdByID);
if (maximumRows > 0)
query = query.Skip(startRowIndex).Take(maximumRows);
return query.ToList<object>();
}
这会导致以下错误:
Unable to cast the type 'System.Int64' to type 'System.Object'. LINQ to Entities only supports casting Entity Data Model primitive types.
你知道我收到这个错误了吗??
谢谢
【问题讨论】:
-
异常在哪一行?
-
@ChristopherRathermel 由于 Linq-To-EF 的工作原理,无论问题的根源在哪里,异常都可能发生在最后一行,并且几乎无用。
标签: c# visual-studio-2010 c#-4.0 entity-framework-4