I am making a simple application for insert, update, delete, select data with Entity Framework
I already made insertion, deletion and select all data.
Now I want to select with where condition with filter of two fields
For ex : I have table with
userid
username
password
email
Now need selection like where email = "" and password = ""
I know how to write query in SQL but having not clues with entity framework
.
Also need to store this result in datatable and looping solution both for learning purpose.
This can help many beginners
use linq query as follows
then if you want to convert into DataTable just call following generic method do convert it
Have to use Linq query like
.ToList()
will give your entire data that comes under your where condition or filter. Now for that you returnDataTable
and easily apply afor
condtion based on yourDataTable
values.Use linq ex:
You can try this
hope this may helpful.
Using Linq To Entities with lambda expression:
Using Linq To Entities the less fancy way:
Lambda expressions are used most of the time. Some people find lambda's less readable. I think it's more a personal taste that depends from your background.
EDIT:
dbContext should be replaced by the name you gave your dbContext/Entities when setting up your Entitiy framework EDMX or Code First Classes.
Account should be replaced by the name of your table/Entity
To loop and edit the results you can do: