score:2
Accepted answer
You can use the overloaded Enumerable.Select method to include the index, then use ToDictionary
:
var dict = EventOccurrencesMappedToPatientMeds
.Select((e, i) => new { Event = e, Index = i + 1 })
.ToDictionary(o => o.Index,
o => (ScheduleEventOccurrenceMedPair)o.Event);
score:1
Use ToDictionary
extension method.
Something like this:
var i = 1;
var resultDictionary = (
from pm in allPtMeds
from e in thisUsersEventOccurrencesPlusEventData
where e.EventContainer.Event.PatientMedId == pm.MedicationId
select new ScheduleEventOccurrenceMedPair
{
PatientMedication = pm,
ScheduledEventOccurrence = e.EventOccurrence
})
.ToDictionary(arg => i++, arg => arg);
Source: stackoverflow.com
Related Articles
- putting linq to objects query result into a typed dictionary
- Linq query result into two objects
- Convert Linq Query Result to Dictionary
- Coercing a LINQ result list of KeyValuePair into a Dictionary - Missing the Concept
- How to get SQL query into LINQ form in C# code
- Using LINQ query result for data source for GridControl c#
- Cannot get more than one result when using System.Linq.Dynamic.Core to query a list of objects that have a member dictionary
- Linq Group By - select a single record in each group into typed result
- How can I code numerous MIN functions into one LINQ to DataSet query
- Getting LINQ query result into a list?
- How to use LINQ to return a query result to a dictionary
- How to use LINQ to query from a list of objects into an existing object?
- LINQ to objects cast result of query
- using linq on datatable and putting result back into datatable with same format
- Unable to collect the result of my LINQ query into a custom Model
- Can I assign the result of a Linq query to the source variable of the same query?
- Moving code from the view into the LINQ query
- Proper Linq Query for objects with many to many relation ship generated with code first entity framework
- How to use ToDictionary to convert a query result into a dictionary
- Linq dynamic order query result by typed input string
- Putting two Linq query data into two separate datatable columns
- LINQ Group By into a Dictionary Object
- Using Linq to group a list of objects into a new grouped list of list of objects
- Filling a DataSet or a DataTable from a LINQ query result set
- LINQ query to return distinct field values from list of objects
- How do you construct a LINQ to Entities query to load child objects directly, instead of calling a Reference property or Load()
- Can I select multiple objects in a Linq query
- LINQ Select into Dictionary
- How To Project a Line Number Into Linq Query Results
- How to convert LINQ query result to List?
- OrderBy on List<string> property
- Paging with LINQ?
- Can't use foreach on a anonymous type
- CASE or IF Statement in Linq Query?
- LINQ query for finding one item in list AND verifying list does not contain another item
- Updating Telerik Rad Grid?
- How do I cache an IQueryable object?
- join datatable and collection and return a listin LINQ C#
- SQL to LINQ converter required, any idea?
- Entity Framework Core count does not have optimal performance
- LINQ subquery with multiple columns
- LINQ query for a forum
- Linq query to return all records with select new statement
- How to calculate sum of amount for each 5 weeks before in linq?
- LINQ query returning objects with property value of specific subtype
- Compare two datatables using two columns in each and return a list of non-matching records
- How to join a one-to-many relationship in Entity Framework?
- How to get an ordered list detail using LINQ
- The nested query is not supported. Operation1='UnionAll' Operation2='MultiStreamNest'
- Better Enumerable.Range for both ascending and descending ranges?