Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

How can i handle the Linq error "Sequence contains no matching element"

$
0
0

Hi 

i have the linq as follows:

orderList and ordergroup are 2 lists 

  foreach (var obj in orderList)     

{   

       obj.Name = ordergroup.First(x => x.Id == obj.orderid).name;             

If there is no match found then i get the above error "Sequence contains no matching element" and it throws an exception . How can i avoid this ?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>