Created
January 11, 2018 00:07
-
-
Save dcomartin/89f16240dba85c895efce5cf43f585cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create your POCO class | |
public 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment