Last active
April 11, 2019 15:32
-
-
Save Stuyk/2ed612997088854125945eb570b47c0d to your computer and use it in GitHub Desktop.
Get By Collection / Selection Collection
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
/// <summary> | |
/// Get an entire collection by Type. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <returns></returns> | |
public static List<T> GetCollection<T>() | |
{ | |
try | |
{ | |
using (var db = new LiteDatabase($"{DatabaseHelper.DatabasePath}/Database.db")) | |
{ | |
return db.GetCollection<T>().FindAll().ToList(); | |
} | |
} catch (Exception ex) | |
{ | |
Console.WriteLine(ex); | |
return null; | |
} | |
} | |
/// <summary> | |
/// Select a collection from the database based on very specific info. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <param name="field"></param> | |
/// <param name="data"></param> | |
/// <returns></returns> | |
public static List<T> GetCollectionFromSelection<T>(string field, BsonValue data) | |
{ | |
try | |
{ | |
using (var db = new LiteDatabase($"{DatabaseHelper.DatabasePath}/Database.db")) | |
{ | |
return db.GetCollection<T>().Find(Query.EQ(field, data)).ToList(); | |
} | |
} catch (Exception ex) | |
{ | |
Console.WriteLine(ex); | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment