so here's the deal , it's my first time developing a windows app for a client , who obviously can't run xampp each time to get the MySQL database running to use the app (cause the app needs to fetch data from the db) , so my question is how do i make a normal windows app whose db starts after starting the app itself? how do most people do it? what db do they use? preferably a free solution
There's a lot of different choices. One commenter mentioned SQLite and SQL Server Compact edition, but if you're running the database locally you should consider if you need something that complex or if it is just overkill.
You may want to consider LINQ or LINQ to XML. LINQ is a query API built into C# .NET, incredibly performant in newer versions of .NET such as Core 3.1, and very cleanly integrated with the C# ecosystem as a whole.
Using bare LINQ, you can load your data on startup from any sort of file format (XML or JSON are popular, I've recently started using FlatBuffers, a standard developed by Google) where you have a List<YourObjectModel>
containing all your database entries. YourObjectModel
here would be a class representing a database row. From there, you can structure queries in one of two ways. There's the SQL style
List<YourObjectModel> dataBase = LoadData();
var result = from entry in database
where entry.FieldA == "something"
select entry;
Or, my preference, the fluent style
var result = database.Where(entry => entry.FieldA == "something");
In practice, you can do anything with LINQ that you could do with SQL, including sorting, pivoting, grouping, etc. LINQ has a lot of benefits, but my favorite selling point is "lazy evaluation", where LINQ doesn't execute your whole query at one time if it can avoid it. If you don't sort, convert the IEnumerable<T>
to a different container, or read the Count
property of the result, LINQ will run the query just long enough to get one result and then have it ready. This can result in a big performance boost if you pass the results into a foreach
loop or some other scenarios.
A bit of anecdotal evidence, I was working on a simple 2D game engine and I needed to sort entities by their Z coordinate so I could draw them from back to front. I was lazy and used a LINQ query to sort a List<GameEntity>
containing over 10,000 objects because it was a one-line solution. It ran great. I went back and implemented a proper sort and found it was actually slower than LINQ. I spent an afternoon trying to implement a sorting algorithm faster than LINQ's and couldn't.