gpt4 book ai didi

c# - Linq to SQL 编写可翻译函数

转载 作者:行者123 更新时间:2023-11-30 16:34:56 27 4
gpt4 key购买 nike

我很确定这个问题的答案是“你不能那样做”或“不,不,你误解了......”,但是:

我有一个 linq 类,thing,它会愉快地执行这个:

 var thingsWithAandB = from t in db.things
where t.propA.HasValue && t.propB.HasValue
select t;

但我经常这样做,所以我想要:

partial class thing
{
public bool hasAandB
{
get
{
return propA.HasValue && propB.HasValue;
}
}
}

然后:

var thingsWithAandB = from t in db.things where t.hasAandB select t;

当然,当我这样做时,我会收到“无法将其转换为 SQL”错误。我知道这是因为在 SQL 查询中间调用方法是不可能的,因为我的代码和数据库是分开的。

有什么方法可以做到这一点?不可能吗?

最佳答案

完全有可能。 Damien Guard (damieng.com) 在他的博客上有一个示例展示了如何做到这一点。

http://damieng.com/blog/2009/06/24/client-side-properties-and-any-remote-linq-provider

关于c# - Linq to SQL 编写可翻译函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2230247/

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