score:5
you need to unwrap the tasks using, await task.whenall(additionalinformation)
then you access the actual result using additionalinformation[0].result
.
so something like this:
var additionalinformation= response.additionalinformation.select( async x => new additionalinformationitem
{
statementcode = x?.statementcode?.value,
limitdatetime = x?.limitdatetime?.item?.value,
statementtypecode = x?.statementtypecode?.value,
statementdescription = x?.statementdescription?.value,
additionalinformationresult = await buildadditionalinformationpointers(x)
});
await task.whenall(additionalinformation);
//this will iterate the results so may not be the most efficient method if you have a lot of results
list<additionalinformationitem> unwrapped = additionalinformation.select(s => s.result).tolist();
score:1
there is actually no way to do this in a simple lambda expression. the async lambda expression will always return a task<t>
. so you can go quick and dirty and call .result
on the task
(don't do it! except if you await first as in liam's answer), or simply initialize a new list and add items in a foreach loop:
var additionalinformation = new list<additionalinformationitem>();
foreach (var x in response.additionalinformation)
{
var item = new additionalinformationitem
{
statementcode = x?.statementcode?.value,
limitdatetime = x?.limitdatetime?.item?.value,
statementtypecode = x?.statementtypecode?.value,
statementdescription = x?.statementdescription?.value,
additionalinformationresult = await buildadditionalinformationpointers(x)
};
additionalinformation.add(item);
}
score:1
await task.whenall
will automatically unwrap the tasks, and will hand you an array with the results.
additionalinformationitem[] additionalinformation = await task.whenall(
response.additionalinformation.select(async x => new additionalinformationitem
{
statementcode = x?.statementcode?.value,
limitdatetime = x?.limitdatetime?.item?.value,
statementtypecode = x?.statementtypecode?.value,
statementdescription = x?.statementdescription?.value,
additionalinformationresult = await buildadditionalinformationpointers(x)
});
);
Source: stackoverflow.com
Related Query
- select from linq statement with await
- Select method missing from intellisense with Linq statement
- Select single column from dataset with LINQ
- Select Distinct List of Words from Array with LINQ
- Group items and select specific item from each group with LINQ
- Efficiently select random rows from large resultset with LINQ (ala TABLESAMPLE)
- When selecting an anonymous type with LINQ from EF, is there no way to run a method on an object as you select it?
- Select only subclasses from collection with Linq
- How to use If statement during select from Linq to Datasets
- I'm trying to simplify with linq a statement that takes 2 lists of numbers and subtracts the first one from the second one
- how to deal with exception in LINQ Select statement
- Select data from multiple unrelated tables with LINQ to Entity Framework
- LINQ to select a column with max date from a group
- How to select multiple columns from dataset into a string list with LinQ
- How to select distinct employees with LINQ based on ID from an employee collection where employee 's salary is 2nd highest?
- creating Linq to sqlite dbml from DbLinq source code
- Select Max value from sublist with LINQ
- How to select a rectangle from List<Rectangle[]> with Linq
- JSON.net linq can not select node with where statement
- Linq query with select needed to get specific properties from a list
- Linq to sql - Join 2 tables, select 1 row from right table with a 1 to many relationship
- C# LINQ - Select statement that compares all properties of a class with a different instance of the same class?
- select from a list with field name and field value with linq (similar to select command)
- Is there a LINQ statement that can select an object from an enumeration based on a max of one of its properties?
- Can't add a new record with an integer value into database by using linq from code C#
- VB.Net Linq with datatables - select from one table what does not exist in the other
- Using Linq to select into an object with children from Json
- LINQ Select statement with EF - object initializer reuse assignment
- Efficient SQL from LINQ statement with joins and aggregate?
- How to select an id from a xml element with linq
More Query from same tag
- Get list of titles from xml files
- How does the LINQ RefreshMode work?
- How do I ignore/remove non-number values from linq query results C#
- Linq to entities DbQuery object is failing hard
- Cannot use ternary operator in LINQ query
- Create a database from a DataContext with integrated security
- How to pass dictionary values without having to iterate using a loop in c#
- Querying a DataTable using LINQ
- How can I group by the difference between rows in a column with linq and c#?
- Is a Collection of Expression<Func<T, TProp>> possible?
- LINQ - Distinct is ignored?
- linq - Substitute Non-Generic Lambda Expression for Generic Lambda Expression
- LINQ 'AsEnumerable' and the Entity Framework
- Take all the same elements from list with LINQ
- Selecting a record where value falls between two strings in LINQ2SQL
- Convert var to List<T> in c#
- Merging 2 lists in C# with a combiner lamba
- Querying Datatable DBNull using Linq Query
- Select rows with LINQ from List<Dictionary<string, object>>
- How to get elements of a List of Lists in C# using linq?
- every Parameter object property that is not null, to be added to expression predicate as a condition
- Doing a Cast Within a LINQ Query
- How to build where clause in SQL Server?
- Entity Framework Core: Request for Composite Table (Composite Key)
- Dynamic filter with LINQ (EntityFramework)
- LINQ to Entities Include() does not work
- Merge items of list based on common property
- DateTime and LinqToEntities
- Another Permutation Word Conundrum... With Linq?
- Where clause on Linq Extension method