This article is a mirror article of machine translation, please click here to jump to the original article.

View: 4251|Reply: 3

[Source] LiteDB Embedded Database for .NET tutorial

[Copy link]
Posted on 5/21/2023 6:27:16 PM | | | |
I once saw a joke on the Internet that saidUse Blazor+LiteDB to draw prototypes of invincible existenceRoughly speaking, it means that the prototype drawing is good, the function is also realized, and then the development efficiency and speed are also very fast.

LiteDB database

LiteDB is a small, fast, and lightweight NoSQL embedded database.

Official Website:The hyperlink login is visible.
GitHub address:The hyperlink login is visible.
LiteDB.Studio Visual GUI Tools:The hyperlink login is visible.

  • Serverless NoSQL document storage
  • Simple API similar to MongoDB
  • 100% C# code, supports .NET 3.5 / .NET 4.0 / NETStandard 1.3 / NETStandard 2.0, single DLL (less than 300 kb)
  • Support thread and process security
  • Support for documentation/action-level ACID
  • Support for data restoration after write failure (log mode)
  • Data file encryption can be done using DES (AES) encryption algorithms
  • You can use the feature or fluent mapping API to map your POCO class to BsonDocument
  • Stores file and streaming data (MongoDB-like GridFS)
  • Single-data file storage (similar to SQLite)
  • Support for fast search based on document field indexes (up to 16 indexes per collection)
  • Support for LINQ queries
  • Shell Command Line - Try this online version
  • Quite fast - here is the comparison with SQLite
  • Open source and free for everyone - including commercial applications
  • Can be installed from NuGet: Install-Package LiteDB


LiteDB vs. SQLite

Both are actually small databases, and neither needs to install a separate database service, and the database is just a separate file;
It supports cross-platform and can be used on Windows, Linux, and mobile;
LiteDB is a non-relational database, and SQLite is a relational database
Performance comparison:The hyperlink login is visible.



.NET 7 uses LiteDB databases

First, create a new .NET 7 project and install the LiteDB database using the nuget command, the command is as follows:

Create a demo database and try to insert 100000 pieces of data with the following code:

Inserting 100,000 pieces of data, it feels like the whole program took 2 seconds.The disk size is 30.5 MBcan be queried using the LiteDB.Studio tool, as shown in the following image:



About database connection strings:The hyperlink login is visible., for example:

LiteDB offers 2 types of connections:DirectandShared. This affects how the engine opens data files.

Direct: The engine will open the data file in exclusive mode and keep it open until Dispose(). Another process cannot open the data file.This is the recommended mode and the default modeBecause it is faster and cacheable.
Shared: The engine closes the data file after each operation. The lock is made using Mutex. This is more expensive, but you can open the same file from multiple processes.

Trying to perform a query operation is also very fast, as follows:



LiteDB stores files

LiteDB also supports storage file operations, that is, you can store images, documents, tables, and other content of websites directly into the LiteDB database, the code is as follows:

(End)





Previous:ASP.NET Core (nineteen) uses BackgroundService to run background tasks
Next:Aspose(1)Aspose.Words populates the table into a word document
 Landlord| Posted on 5/21/2023 6:28:15 PM |
[Actual combat]. NET/C# Create an SQLite database and simply add, delete, modify
https://www.itsvse.com/thread-10192-1-1.html
 Landlord| Posted on 5/16/2025 10:45:13 AM |
H2 Database is an open-source embedded database engine written in Java language that is not limited by the platform, and H2 Database provides a very convenient web console for operating and managing database content. H2 Database also provides compatibility mode, which can be compatible with some mainstream databases, so it is very convenient to use H2 Database as a database in the development period.
 Landlord| Posted on 7/17/2025 4:27:17 PM |
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com