tags:

views:

30

answers:

2

I m new in Linq and i didnt understang this query

Db.Enum_Countries .Where(p=>p.id==id)
.Single()
.Title)

Can you help me....

A: 

Where(...) finds all the countries with the given id. Single(...) ensures that only one country has that id, and returns just that country.

In summary, it means, "The title of the only country whose id is id".

Marcelo Cantos
Just wanted to add for clarity that there MUST be EXACTLY ONE country. If there are zero, or 2 or more, then an exception is thrown.
roufamatic
A: 

You have a list of things -- presumably countries -- which have a Title property. You want to find the single item in that list whose id property matches the id variable you have in scope. Then you want to access its Title property.

You could also write:

db.Enum_Countries.Single(p => p.id == id).Title
Chris Farmer