public static SecondaryObjectCollection Where(WhereDelegate <SecondaryObjectColumns> where, OrderBy <SecondaryObjectColumns> orderBy = null, Database database = null) { database = database ?? Db.For <SecondaryObject>(); var results = new SecondaryObjectCollection(database, database.GetQuery <SecondaryObjectColumns, SecondaryObject>(where, orderBy), true); return(results); }
/// <summary> /// Return every record in the SecondaryObject table. /// </summary> /// <param name="database"> /// The database to load from or null /// </param> public static SecondaryObjectCollection LoadAll(Database database = null) { SqlStringBuilder sql = new SqlStringBuilder(); sql.Select <SecondaryObject>(); Database db = database ?? Db.For <SecondaryObject>(); var results = new SecondaryObjectCollection(sql.GetDataTable(db)); results.Database = db; return(results); }
private static SecondaryObject OneOrThrow(SecondaryObjectCollection c) { if (c.Count == 1) { return(c[0]); } else if (c.Count > 1) { throw new MultipleEntriesFoundException(); } return(null); }
public void ShouldBeAbleToRestore() { SQLiteDatabase toBackup = GetTestDatabase(MethodBase.GetCurrentMethod().Name); toBackup.MaxConnections = 500; FillDatabaseWithTestData(toBackup); MainObjectCollection main = MainObject.LoadAll(toBackup); SecondaryObjectCollection secondary = SecondaryObject.LoadAll(toBackup); TernaryObjectCollection ternary = TernaryObject.LoadAll(toBackup); List <IRepository> repos = new List <IRepository>(); repos.Add(new DaoRepository(new SQLiteDatabase("BackupRepo_{0}"._Format(MethodBase.GetCurrentMethod().Name), "BackupRepoDb"))); repos.Add(new ObjectRepository("ObjectRepo_{0}"._Format(MethodBase.GetCurrentMethod().Name))); foreach (IRepository repo in repos) { DaoBackup backup = new DaoBackup(typeof(MainObject).Assembly, toBackup, repo); backup.Backup(); SQLiteDatabase restored = GetTestDatabase("{0}_Restored_For_{1}"._Format(MethodBase.GetCurrentMethod().Name, repo.GetType().Name)); //MsSqlDatabase restored = new MsSqlDatabase("192.168.0.59", "DaoRef", new MsSqlCredentials { UserName = "******", Password = "******" }); HashSet <OldToNewIdMapping> restoreInfo = backup.Restore(restored); List <string> keys = restoreInfo.Select(i => i.Uuid).ToList(); main.Each(new { Uuids = keys }, (ctx, m) => { Expect.IsTrue(ctx.Uuids.Contains(m.Uuid)); }); secondary.Each(new { Uuids = keys }, (ctx, s) => { Expect.IsTrue(ctx.Uuids.Contains(s.Uuid)); }); ternary.Each(new { Uuids = keys }, (ctx, t) => { Expect.IsTrue(ctx.Uuids.Contains(t.Uuid)); }); restoreInfo.Each(ri => { OutLineFormat(ri.PropertiesToString(), ConsoleColor.DarkYellow); }); OutLineFormat("Repository of type {0} passed restore test", ConsoleColor.Green, repo.GetType().Name); } }
/// <summary> /// This method is intended to respond to client side Qi queries. /// Use of this method from .Net should be avoided in favor of /// one of the methods that take a delegate of type /// WhereDelegate<SecondaryObjectColumns>. /// </summary> /// <param name="where"></param> /// <param name="database"></param> public static SecondaryObjectCollection Where(QiQuery where, Database database = null) { var results = new SecondaryObjectCollection(database, Select <SecondaryObjectColumns> .From <SecondaryObject>().Where(where, database)); return(results); }