public void GeneralTest() { DbStructureGateway g = DbStructureGateway.Instance; g.CreateTable(typeof(NewsItem)); Assert.IsTrue(g.IsValid(typeof(NewsItem)), g.LastError); Assert.IsFalse(g.IsValid(typeof(NewsItem2))); DbTableCheckResult result = new DbTableCheckResult(DbAccessor.Instance); result.Build(typeof(NewsItem2)); Assert.AreEqual(2, result.FieldsToCreate.Count); Assert.AreEqual(1, result.FieldsToUpdate.Count); g.DropTable(typeof(NewsItem)); g.CreateTable(typeof(NewsItem2)); Assert.IsTrue(g.IsValid(typeof(NewsItem2))); Assert.IsFalse(g.IsValid(typeof(NewsItem))); result = new DbTableCheckResult(DbAccessor.Instance); result.Build(typeof(NewsItem2)); Assert.AreEqual(0, result.FieldsToCreate.Count); Assert.AreEqual(0, result.FieldsToUpdate.Count); }
///<summary> /// Updates database table to match passed Type /// /// Notice: /// - affrects only added and changed fields /// - doesn't remove unused columns from database /// - ignores primary key and indexes ///</summary> ///<param name="type">Type to check</param> ///<returns>true on success</returns> public bool AlterTable(Type type) { DbTableCheckResult result = new DbTableCheckResult(accessor); result.Build(type); accessor.AlterTable(result); return(true); }