How can I embed a SQLite Database in a .NET DLL and then use it from C#?

前端 未结 5 1812
星月不相逢
星月不相逢 2020-12-16 01:30

I\'m currently working on some evaluation work for a project that I\'m planning.

I recently looked at solutions for a data storage mechanism for my application and w

5条回答
  •  旧巷少年郎
    2020-12-16 01:49

    I don't think storing data in DLL is a good idea, but there is a dirty way to do it.

    To load data from DLL:

    1. Use System.Reflection.Assembly to load a string from DLL file. (The string is dump of DB)
    2. Create empty SQLite DB in memory.
    3. Use the loaded string as a query to DB to restore its content.

    Now you can make any queries in memory.

    To save data to DLL:

    1. Dump DB content into a string.
    2. Create temporary file containing SQL-dump wrapped in C# code.
    3. Compile it using "csc" (or "gmcs" in Mono).

    It's stupid, but it should work. Hope you will never code that way.

提交回复
热议问题