Use .FirstOrDefault()
to get the first element matching your Where()
, or null
when none match:
var oCustomer = oCust.Where(x => x.CountryCode == "US").FirstOrDefault();
also discuss how to solve the above scenario using auto mapper with sample code.
You’ve done this under various of your questions: “Here is my question, oh and please explain this related concept to me with sample code”.
This is not how Stack Overflow works. Search the web for automapper, find their Getting Started page and ask a new question if you can’t figure out how to use it.
3
solved How to cast a type to specific class in c# 4.0 after querying LINQ to Object