techno
techno

Reputation: 6500

Filter element from SQL Database table using LINQ

I'm trying to learn LINQ. I have

var mydata = from k in db.emp_mains select k.empname.Equals("me");

But after this statement i the auto complete wont complete the table fields name

foreach(var x in mydata)
{
     ---> Autocomplete not working  Console.WriteLine(x.empname);
}

Why is this happening? Kindly advice.

Upvotes: 0

Views: 34

Answers (2)

Austin T French
Austin T French

Reputation: 5131

What you want is to filter with the where statement:

var myData = from k in db.emp_mains
where k.empname == "me"
select name

I much prefer the linq syntax like this for simple statements however:

var myDate = dc.emp_mains.where(w => w.empname == "me").Select(s => s.name).ToList();

Either way, you should get a list on names.

Upvotes: 1

Sunil
Sunil

Reputation: 3424

Your condition need to go into where clause

var mydata = (from   k in db.emp_mains 
              where  k.empname.Equals("me")
              select k
             ).ToList();

Upvotes: 2

Related Questions