gpt4 book ai didi

c# - 无法将类型 'System.Int64' 转换为类型 'System.Object'。 LINQ to Entities 仅支持转换实体数据模型基元类型

转载 作者:太空狗 更新时间:2023-10-29 17:49:44 25 4
gpt4 key购买 nike

我创建了一个 EF 4C# 来获取一些数据。我正在使用 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.

你知道我收到这个错误吗??

谢谢

最佳答案

一旦您到达 ToList 调用,您希望在 C# 中执行它,而不是在数据库中。使用 AsEnumerable 作为一种表达方式,“停止在数据库中做这些事情,用 C# 做吧。”

在末尾 ToList 之前添加它,以便在数据库上完成其他所有操作。

关于c# - 无法将类型 'System.Int64' 转换为类型 'System.Object'。 LINQ to Entities 仅支持转换实体数据模型基元类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10284303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com