Are there any classes that can be queried / modified like a SQL DB but is entirely local and internal to the program?
I am aiming to write a program that needs to have a local data source with all data saved in a file, but I would like to be able to query this information store just as I would a DB; LINQ compatibility would be a开发者_开发知识库 huge plus.
The data would only be accessible when the program was running meaning, there would be no other process running to serve the data such as SQL server.
You can use SQL Server Compact Edition. It is hosted in-process and uses a .sdf
file locally. It works with LINQ and the LINQ-to-SQL designer. To use it, you'll just need to add a reference to System.Data.SqlServerCe.dll. It's very lightweight, familiar, and has excellent support in Visual Studio.
On a side note, the Visual C++ IDE team is using this database for their C++ IntelliSense information in Visual Studio 2010, replacing the old .ncb files. Based on their stated goals going into the project (rewriting the C++ IDE for massively improved IntelliSense performance and stability), seeing it used here says a lot.
You could use SQLite with DBLinq.
XML comes to mind. I am not sure if you are trying to actually save the data to a file or if you want to keep it entirely in memory. But with XML you can use LINQ to XML for your querying and it's got good structure, easy to save out to a file, etc.
DataSets
allow multiple tables of data to be held and processed in memory.
LINQ to DataSets is part of .NET 3.5: http://msdn.microsoft.com/en-us/library/bb386977.aspx
This would allow a custom storage format, if you write the serialisation and deserialisation to a DataSet for your format.
If you don't want to create your own file format, SQL Server Compact Edition (or SQL Express) would probably be an easier option (as in other answer).
精彩评论