Member [class] does not support SQL translation

I get the following error:

Error message: Member of 'Company.ProductCore.Core.Domain.Account.Email' does not support SQL translation.

My method is as follows:

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; } 

There is a getter / setter method in my account class that provides email:

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

And my email is a LINQ object.

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

Help rate, thanks ...

+4
source share
1 answer

I think this is what you need (you need to refer directly to the email address through a known mapping), but I cannot 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(); 

Why? part:
In short, LINQ has no information about the meaning of what this property is ... and cannot make an SQL query because it does not know, so you get a runtime error when it tries to generate a query from an expression tree.

You cannot use a property in a query if LINQ does not know which table / column / function it maps to without it ... it just cannot convert it to or from SQL.

+2
source

Source: https://habr.com/ru/post/1310685/


All Articles