I have the following one-to-many relationship between two objects.
Parent --> IList<Child>
Now I have a List of Parents , and I want the first child of each parent in the list.
What is the best way to do this with Linq?
parents.Where(p => p.Children.Any()).Select(p => p.Children.First());
You can iterate through each "parent" and find the first of its descendants:
parent.FirstOrDefault(child => parent.Children.First());
parent.child.FirstOrDefault ();
Source: https://habr.com/ru/post/1313761/More articles:How to disable Coldfusion for one site? - coldfusionDoes anyone have any work on apache facebook graphics today? - facebookGit and massive problems with spaces - gitHow to redirect a thick interface? - c #Moving an ASP.NET site from http to https? - asp.netAndroid SQLite Query and using a cursor to handle multiple rows - javaClosing MySQL connection after each request - phpFacebook like: Uncaught TypeError: Object # doesn't have a 'provide' method - javascriptDetermine Maven build status (SUCCESS / ERROR) from Maven plugin - maven-2NSURLConnection crashes due to poor access - redirectAll Articles