0
votes

I'm using ADO.Net to access a database. But right now, I'm trying to recover some information, but I can't remember how to use the .where<>clause.

Here the code:

string sql = "Id = '" + identifier + "'";
USER u = db.USER.Where(sql).First<USER>();

Where dbis the Entity Model, but I fail to remember how to use this Where<> clause...

Anybody can help?

2

2 Answers

2
votes

you can use lambda expression :

User u=db.USER.Where(x=>x.Id==identifier).First();

or you can write your query this way :

User u=from us in db.Users Where us.Id==identifier select us ;

and here is another way to use lambda expressionn :

User u=db.Users.First(x=>x.Id==identifier);
1
votes

Do you mean LINQ

USER u = db.USER.Where(x => x.Id == identifier).First<USER>();

This post on Parameterized IN clauses with ADO.NET and LINQ might be helpful for reference