gpt4 book ai didi

c# - 无法使用 Select(x => Func(x)) 转换为 SQL

转载 作者:行者123 更新时间:2023-11-30 19:50:14 25 4
gpt4 key购买 nike

我正在慢慢学习 LINQtoSQL 的来龙去脉,但这让我感到困惑。

这是我的声明:

IQueryable<IEvent> events = (from e in db.getEvents()
select e).Select(x => SelectEvent(x, null));

SelectEvent 的作用可以在 this answer here 中解释。 .我没有使用 .toList() 函数,因为我不希望可能有数千条记录进入内存。

public IEvent SelectEvent(SqlServer.Event ev, EventType? type) {
// Create an object which implements IEvent
// I don't have the code in front of me, so forgive the lack of code
}

我的问题实际上是关于 Select() 方法的。我收到“无法转换为 SQL”错误,错误消息中列出了 Select()

对此一无所知:-/。

最佳答案

Linq to SQL 无法将任意函数调用转换为 SQL。它不知道函数的作用。您必须使用表达式构造 SelectEvent 所做的任何事情。

或者,如果您只想在查询通过数据库后将对象映射到其他对象,只需在循环结果时执行此操作,或者创建一个包装生成器来为您执行此操作。

关于c# - 无法使用 Select(x => Func(x)) 转换为 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2556790/

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