gpt4 book ai didi

c# - Linq-To-Sql 查询中的模糊调用

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

我对 Linq-To-SQL 还是有点陌生​​,当我尝试使用连接运算符(执行与 SQL 内部连接等效的操作)时遇到问题。

获取用户的所有偏好:

return (from u in DataContext.UserPreference
join p in DataContext.Preference on p.Id equals u.PreferenceId
where u.UserId = userId
select p).ToList();

Visual Studio 告诉我查询中的“连接”运算符是 Enumerable 类和 Queryable 类之间的“模糊调用”。

有什么办法可以解决这个问题吗?

最佳答案

您的连接表达方式错误 - 您应该先使用 u,然后使用 p:

return (from u in DataContext.UserPreference
join p in DataContext.Preference on u.PreferenceId equals p.Id
where u.UserId == userId
select p).ToList();

基本上,您在联接的左侧使用第一个范围变量,在右侧使用第二个变量。

通常这种错误是由编译器发现的,它会准确地指出问题所在。我不知道为什么在这种情况下没有,但无论哪种方式,上述方法都应该是解决方法。

关于c# - Linq-To-Sql 查询中的模糊调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7058466/

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