Hi @Spideregg , Welcome to Microsoft Q&A,
You can try to optimize the code by using reflections, but to be honest, if you are using a very large database it will be better if you can change your approach and use either a Database or try to use more efficient data structures. A bit of explanation regarding this :
Using a Database: When dealing with large datasets, it can be more efficient to use a database to store and manipulate your data. Databases are designed to handle large amounts of data and can perform operations like sorting, filtering, and aggregating data much faster than you could by manually coding these operations in C#. There are many types of databases, such as SQL Server, MySQL, and MongoDB, and the best one to use depends on your specific needs.
Using More Efficient Data Structures: Data structures are a way of organizing and storing data so that they can be accessed and worked with efficiently. They define the relationship between the data, and the operations that can be performed on the data. Some data structures are more efficient than others for certain types of operations. For example, if you frequently need to look up values based on a key, a Dictionary<TKey, TValue> can be more efficient than a List<T> because it can look up values in constant time.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.