会员[类]没有支持转换为SQL [英] The member [class] has no supported translation to SQL

查看:117
本文介绍了会员[类]没有支持转换为SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

错误消息:成员
  Company.ProductCore.Core.Domain.Account.Email
  已经没有支持转换为SQL。

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;

        }

我的帐户类有一个getter / setter方法​​暴露电子邮件:

My Account class has a getter / setter that exposes Email:

 public Email Email
        {
            get { return _email; }
            set { _email = value; }
        }

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

And my Email is a LINQ object.

我有一种感觉,问题是,我使用LINQ对象为我推荐
属性?我是新来的LINQ和真的不知道为什么会这样。

I have a feeling that the problem is that I am using a LINQ object for me Email property? I am new to LINQ and am not really sure why this is happening.

帮助AP preciated,谢谢...

Help appreciated, thanks...

推荐答案

我的认为的,这是你追求的(你需要直接引用的电子邮件地址,通过已知的映射),但我不能100%肯定不知道你的结构:

I think this is what you're after (you need to reference the email address directly, through a known mapping), but I can't be 100% sure without knowing your structure:

            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查询,因为它不知道,所以你会得到一个运行时错误p $ pssion树。

The why? part:
In short, LINQ has no mapping knowledge of what that property is...and can't make a SQL query because it doesn't know, so you'll get a runtime error when it tries to generate a query from the expression tree.

您可以在查询LINQ,除非知道什么表/列不使用属性/功能映射到,如果没有这个...它根本无法将其转换为或SQL。

You can't use a property in a query unless LINQ knows what table/column/function it maps to, without this...it simply can't convert it to or from SQL.

这篇关于会员[类]没有支持转换为SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆