Query To retrieve Desc. From Id In Linq
I m new in Linq and i didnt understang this query
Db.Enum_Countries .Where(p=>p.id==id)
.Single开发者_JS百科()
.Title)
Can you help me....
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
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
".
精彩评论