I was trying to find a way to query a C# list as a data base using a string sql query, for example :
List<Customer> customers = new List<Customer>(){
new Customer(){Name = "joe", Age = 20},
new Customer(){Name = "john", Age = 25}
};
string query = @"Select * from customers";
List<Tuple> tuples = EntityDB.query(customers, query);
Console.Writeline(tuples[0][0]); //prints "joe"
I got several requirements that needs to be met using this feature,
- it needs to support dynamic SQL queries (string queries), because I will need to extract specific rows from this list, and the filtering is not predefined. (linq is not helpful here)
- it needs to be able to support functionalities on several rows (like Average, Count...) exactly like SQL.
- it needs to support extraction of specified columns exactly like SQL (select column1, column2...)
I dont have a SQL sever on, I dont have additional mdf DB, its just this list of objects of customers, is there a way to do it?
my motivation for this is the ability to extract specific info from this list to a 2D table and output it to excel, but the row and column filtering is not predefined, and multi-row operations are needed, users will be able to specify the exact info they want to extract like with SQL query.
DateOfBirthrather thanAge, becauseAgeis dependent on when your code executes, and how long your objects might stay in memory. What happens when your code runs around New Year's Eve / New Year's Day…?DateOfBirthis independent from all that, and the correctAgecan be easily derived from it at any time.