public void TestIdentityColumns(bool batchMode) { _app = new IdentityTestsEntityApp(); Startup.ActivateApp(_app); //if(Startup.ServerType == Data.Driver.DbServerType.SQLite) DeleteAllData(); // We create session this way to set the batch mode flag var ctx = new OperationContext(_app); IEntitySession session = new EntitySession(ctx, options: batchMode ? EntitySessionOptions.None : EntitySessionOptions.DisableBatchMode); var john = session.NewEntity <IPerson>(); john.Name = "John S"; //john.Name = "Джон Ш"; //Russian var car1 = session.NewEntity <ICar>(); car1.Model = "Beatle"; car1.Owner = john; car1.CoOwner = null; var car2 = session.NewEntity <ICar>(); car2.Model = "Explorer"; car2.Owner = john; Assert.IsTrue(car1.Id < 0, "Car ID is expected to be <0 before saving."); session.SaveChanges(); //Check that Identity values immediately changed to actual positive values loaded from database Assert.IsTrue(john.Id > 0, "Invalid person ID - expected positive value."); Assert.IsTrue(car1.Id > 0, "Invalid car1 ID - expected positive value."); Assert.IsTrue(car2.Id > 0, "Invalid car2 ID - expected positive value."); //Start new session, load all and check that IDs and relationships are correct session = _app.OpenSession(); john = session.EntitySet <IPerson>().Where(p => p.Name == "John S").Single(); var cars = session.GetEntities <ICar>().ToList(); car1 = cars[0]; car2 = cars[1]; Assert.IsTrue(john.Id > 0 && car1.Id > 0 && car2.Id > 0, "IDs expected to become > 0 after saving."); Assert.IsTrue(car1.Owner == john, "Owner expected to be John"); Assert.IsTrue(car2.Owner == john, "Owner expected to be John"); // Testing list.Contains with long (bigint) values, used to fail for SQL Server var longArray = new long[] { long.MaxValue - 10, long.MaxValue - 9, long.MaxValue - 8 }; // we just test that this does not blow up var someCars = session.EntitySet <ICar>().Where(c => longArray.Contains(c.Id)).ToList(); var sql = session.GetLastCommand().CommandText; Assert.AreEqual(0, someCars.Count); }//method
public void TestIdentityColumns(bool batchMode) { _app = new IdentityTestsEntityApp(); Startup.ActivateApp(_app); //if(Startup.ServerType == Data.Driver.DbServerType.SQLite) DeleteAllData(); // We create session this way to set the batch mode flag var ctx = new OperationContext(_app); IEntitySession session = new EntitySession(ctx, options: batchMode ? EntitySessionOptions.None : EntitySessionOptions.DisableBatchMode); var john = session.NewEntity <IPerson>(); john.Name = "John S"; var car1 = session.NewEntity <ICar>(); car1.Model = "Beatle"; car1.Owner = john; car1.CoOwner = null; var car2 = session.NewEntity <ICar>(); car2.Model = "Explorer"; car2.Owner = john; Assert.IsTrue(car1.Id < 0, "Car ID is expected to be <0 before saving."); session.SaveChanges(); //Check that Identity values immediately changed to actual positive values loaded from database Assert.IsTrue(john.Id > 0, "Invalid person ID - expected positive value."); Assert.IsTrue(car1.Id > 0, "Invalid car1 ID - expected positive value."); Assert.IsTrue(car2.Id > 0, "Invalid car2 ID - expected positive value."); //Start new session, load all and check that IDs and relationships are correct session = _app.OpenSession(); john = session.EntitySet <IPerson>().Where(p => p.Name == "John S").Single(); var cars = session.GetEntities <ICar>().ToList(); car1 = cars[0]; car2 = cars[1]; Assert.IsTrue(john.Id > 0 && car1.Id > 0 && car2.Id > 0, "IDs expected to become > 0 after saving."); Assert.IsTrue(car1.Owner == john, "Owner expected to be John"); Assert.IsTrue(car2.Owner == john, "Owner expected to be John"); }//method