score:1
You could save your in-memory users in a KeyedCollection.
score:2
Assuming the primary key is a reference type, you'd only be storing a reference to the primary key twice.
Have you tried using Dictionary<,>
and found it doesn't work well enough? It's certainly the most natural solution. KeyedCollection<,>
(suggested by Mark) would certainly work too, but requires you to derive from the class - and I wouldn't like to guarantee it'll actually save any memory. (You'd need to know the implementation details - it could easily just use a Dictionary internally, for example.)
Source: stackoverflow.com
Related Articles
- Are there any alternatives to using List.Single to get an element with a primary key?
- How to update an element with a List using LINQ and C#
- How do I get the Nth largest element from a list with duplicates, using LINQ?
- Searching Record List using single parameter Id and compare with multiple columns EF
- Create a tree structure in linq with a single list source with parent - child as strings of an object
- Is there a way to show a single employee with each of his projects using a query in Entity Framework
- c# Linq or code to extract groups from a single list of source data
- Is there any way to get a JSON object as a list of view models and update records in database with single AJAX call?
- get list from xml using linq based on true if there is no true then select false condition tag element in c#
- How to merge a list of lists with same type of items to a single list of items?
- Populate a list with a specific range of numbers by using LINQ
- Using FluentValidation's WithMessage method with a list of named parameters
- Find first element of certain type in a list using LINQ
- Flatten List<string[]> into single string with one line for each element
- How to remove an element from an xml using Xdocument when we have multiple elements with same name but different attributes
- Select all unique combinations of a single list, with no repeats, using LINQ
- Test if an IEnumerable<T> contains 1 element without counting or using Single
- Comparing each element with each other element in a list
- Deleting multiple records with Entity Framework using a single LINQ query
- List shows 4 items in debugger even if filled with exactly one element
- Add quotes at the beginning and end of each element in list using LINQ
- Using LINQ to Get Sum/ Average of a List with custom objects
- How to get all elements except the n'th element in a List using Linq
- Return List with Maximum Count using Linq
- Using async with Entity Framework select list of type IQueryable<T>
- How to remove first occurence of element in List C# with LINQ?
- Using LINQ to delete an element from a ObservableCollection Source
- C# - Error CS1928: Checking for list element with derived class
- Select all unique combinations of a single list, with no repeats, using LINQ (Part 2)
- How to convert list of objects with two fields to array with one of them using LINQ
- Paging in LINQ+MVC with a randomly ordered collection
- How to get an EF query to compile the most optimised SQL?
- Get sum of values in between two dates with same month references
- Parsing XDocument using LINQ
- How can you use LINQ to find Azure AD users with specific licenses using the Azure AD Graph API Client Library 2.0
- having trouble performing LINQ's ThenBy inside a loop
- linq to sql query optimization suggestions needed
- How to change calculation type using lambda expression?
- Create a linq subquery returns error "Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operator"
- Linq select strange effect
- access entity query result from another func
- LINQ to SQL Right Outer Join
- Linq, Expressions, NHibernate and Like comparison
- Why is ToLookup() dependent on load options in Linq2Sql?
- Left Outer Join That Returns Null Right Side In Addition To The Matching Rows
- filling combo box using LINQ query (distinct)
- Return a list of record with Linq
- LINQ TO Nhibernate Count
- Alphanumeric sorting using LINQ
- How do I optimize this SharePoint query for Terms?