3

I have an Entity Framework model semi-working right now, but I'm having trouble performing a query to return database records with a Where() clause.

I am trying to line:

db.BlackstoneUsers.Where(u => u.Email == User.Email); 

but I get the exception:

Expression cannot contain lambda expressions

I think this should be simple, but I'm just learning Entity and LINQ/Lambda.

Does anyone have any pointers?

10
  • What is User or User.Email? Is it just a straight string, or is it some sort of database object as well? Commented Jul 17, 2013 at 20:43
  • @StevenVondruska User is a database model and User.Email is a string Commented Jul 17, 2013 at 20:44
  • how are you running the program? Commented Jul 17, 2013 at 20:45
  • @Jonesy It's a web project run in Azure Commented Jul 17, 2013 at 20:46
  • 2
    Are you trying to check this in the watch window in the debugger? The debugger doesn't support lambda expressions. Commented Jul 17, 2013 at 20:49

2 Answers 2

1

try setting the email outside the call

var email = User.Email
db.BlackstoneUsers.Where(u => u.Email == email); 
Sign up to request clarification or add additional context in comments.

3 Comments

What would this accomplish?
@JeroenVannevel the email would be converted to a constantexpression which can be translated by the EntityFramework code
@brett only send constants to your EntityFramework expressions
0

Your code looks fine but what are you doing with the object?

Just this code will not work.

db.BlackstoneUsers.Where(u => u.Email == email); 

But what if you do like

var something = db.BlackstoneUsers.Where(u => u.Email == User.email); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.