gpt4 book ai didi

c# - 成员 [class] 不支持转换为 SQL

转载 作者:行者123 更新时间:2023-12-04 20:58:53 25 4
gpt4 key购买 nike

我收到以下错误:

Error Message:The member 'Company.ProductCore.Core.Domain.Account.Email' has no supported translation to SQL.



我的方法是这样的:
public Account GetAccountByEmail(string email)
{
Account account;

using (WorkbookDataContext dc = _conn.GetContext())
{
account = ( from a in dc.Accounts
join em in dc.Emails on a.AccountId equals em.AccountId
where a.Email.EmailAddress == email
select a).FirstOrDefault();
}

return account;

}

我的 Account 类有一个公开电子邮件的 getter/setter:
 public Email Email
{
get { return _email; }
set { _email = value; }
}

我的电子邮件是一个 LINQ 对象。

我有一种感觉,问题是我正在为我使用 LINQ 对象
属性(property)?我是 LINQ 的新手,并不确定为什么会发生这种情况。

感谢帮助,谢谢...

最佳答案

我认为这就是您所追求的(您需要通过已知的映射直接引用电子邮件地址),但我不能在不知道您的结构的情况下 100% 确定:

            account = (from a in dc.Accounts
join em in dc.Emails on a.AccountId equals em.AccountId
where em.EmailAddress == email
select a).FirstOrDefault();

为什么?部分:
简而言之,LINQ 没有该属性是什么的映射知识……并且无法进行 SQL 查询,因为它不知道,因此当它尝试从表达式树生成查询时,您将收到运行时错误.

您不能在查询中使用属性,除非 LINQ 知道它映射到哪个表/列/函数,否则……它根本无法将其转换为 SQL 或从 SQL 转换。

关于c# - 成员 [class] 不支持转换为 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2893646/

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