在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:LiteDB开源软件地址:https://gitee.com/ajeelee/LiteDB开源软件介绍:LiteDB - A .NET NoSQL Document Store in a single data fileLiteDB is a small, fast and lightweight .NET NoSQL embedded database.
New v5
Lite.StudioNew UI to manage and visualize your database: DocumentationVisit the Wiki for full documentation. For simplified chinese version, check here. LiteDB CommunityHelp LiteDB grow its user community by answering this simple survey How to use LiteDBA quick example for storing and searching documents: // Create your POCO classpublic class Customer{ public int Id { get; set; } public string Name { get; set; } public int Age { get; set; } public string[] Phones { get; set; } public bool IsActive { get; set; }}// Open database (or create if doesn't exist)using(var db = new LiteDatabase(@"MyData.db")){ // Get customer collection var col = db.GetCollection<Customer>("customers"); // Create your new customer instance var customer = new Customer { Name = "John Doe", Phones = new string[] { "8000-0000", "9000-0000" }, Age = 39, IsActive = true }; // Create unique index in Name field col.EnsureIndex(x => x.Name, true); // Insert new customer document (Id will be auto-incremented) col.Insert(customer); // Update a document inside a collection customer.Name = "Joana Doe"; col.Update(customer); // Use LINQ to query documents (with no index) var results = col.Find(x => x.Age > 20);} Using fluent mapper and cross document reference for more complex data models // DbRef to cross referencespublic class Order{ public ObjectId Id { get; set; } public DateTime OrderDate { get; set; } public Address ShippingAddress { get; set; } public Customer Customer { get; set; } public List<Product> Products { get; set; }} // Re-use mapper from global instancevar mapper = BsonMapper.Global;// "Products" and "Customer" are from other collections (not embedded document)mapper.Entity<Order>() .DbRef(x => x.Customer, "customers") // 1 to 1/0 reference .DbRef(x => x.Products, "products") // 1 to Many reference .Field(x => x.ShippingAddress, "addr"); // Embedded sub document using(var db = new LiteDatabase("MyOrderDatafile.db")){ var orders = db.GetCollection<Order>("orders"); // When query Order, includes references var query = orders .Include(x => x.Customer) .Include(x => x.Products) // 1 to many reference .Find(x => x.OrderDate <= DateTime.Now); // Each instance of Order will load Customer/Products references foreach(var order in query) { var name = order.Customer.Name; ... }} Where to use?
Plugins
ChangelogChange details for each release are documented in the release notes. Code SigningLiteDB is digitally signed courtesy of SignPath License |
请发表评论