Click here to Skip to main content
15,899,937 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Experts


i am new to linq so i am facing default to write some queries

i am having table called Table1 with 2 column(ID,Name),

Now I want Select the 2 column from the table using linq,

in sql we write has

select * from Table1;

how to write in linq?
Posted

I you want to select all values as you said in SQL query is
select * from Table1


for this you can write like:
var result = Table1.AsEnumerable().ToList();


If you want to select values specific to some ID (here I have given 1, you can give any value) you can write like:
var result1 = (from r in Table1.AsEnumerable()
                              where r.Field<int32>("ID")==1
                              select r).ToList();
 
Share this answer
 
v2
Hi,

Try this
C#
from table in Table1
where table.id == tempIdValue
select new { Id = table.Id, Name = table.Name };


I havent tested this. Hope this works.

Regards,
Praneet
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900