public void SingleInheritance_RelationsWorkCorrectly() { using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var objectWithRelations = SingleInheritanceObjectWithRelations.NewObject(); objectWithRelations.ScalarProperty = SingleInheritanceFirstDerivedClass.NewObject(); objectWithRelations.VectorProperty.Add(SingleInheritanceFirstDerivedClass.NewObject()); objectWithRelations.VectorProperty.Add(SingleInheritanceSecondDerivedClass.NewObject()); ClientTransaction.Current.Commit(); } using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var query = new Query(new QueryDefinition("QueryOverUnionView", TestDomainStorageProviderDefinition, "SELECT * FROM [SingleInheritanceObjectWithRelationsView]", QueryType.Collection), new QueryParameterCollection()); var actualObjectWithRelations = ClientTransaction.Current.QueryManager.GetCollection <SingleInheritanceObjectWithRelations> (query) .AsEnumerable().Single(); Assert.IsInstanceOf(typeof(SingleInheritanceFirstDerivedClass), actualObjectWithRelations.ScalarProperty); Assert.That(actualObjectWithRelations.VectorProperty.Count, Is.EqualTo(2)); Assert.That(actualObjectWithRelations.VectorProperty.OfType <SingleInheritanceFirstDerivedClass> ().Single(), Is.Not.Null); Assert.That(actualObjectWithRelations.VectorProperty.OfType <SingleInheritanceSecondDerivedClass> ().Single(), Is.Not.Null); } }
public void AccessingMixinProperties_OfDerivedClass() { SetDatabaseModifyable(); var singleInheritanceFirstDerivedClass1 = SingleInheritanceFirstDerivedClass.NewObject(); ((ISingleInheritancePersistentMixin)singleInheritanceFirstDerivedClass1).PersistentProperty = "value 1"; var singleInheritanceFirstDerivedClass2 = SingleInheritanceFirstDerivedClass.NewObject(); ((ISingleInheritancePersistentMixin)singleInheritanceFirstDerivedClass2).PersistentProperty = "value 2"; var singleInheritanceSecondDerivedClass1 = SingleInheritanceSecondDerivedClass.NewObject(); ((ISingleInheritancePersistentMixin)singleInheritanceSecondDerivedClass1).PersistentProperty = "value 1"; var singleInheritanceSecondDerivedClass2 = SingleInheritanceSecondDerivedClass.NewObject(); ((ISingleInheritancePersistentMixin)singleInheritanceSecondDerivedClass2).PersistentProperty = "value 2"; ClientTransaction.Current.Commit(); var queryWithSingleTableInheritance = from obj in QueryFactory.CreateLinqQuery <SingleInheritanceBaseClass> () where (obj is SingleInheritanceFirstDerivedClass || obj is SingleInheritanceSecondDerivedClass) && (((ISingleInheritancePersistentMixin)obj).PersistentProperty == "value 1") select obj; CheckQueryResult(queryWithSingleTableInheritance, singleInheritanceFirstDerivedClass1.ID, singleInheritanceSecondDerivedClass1.ID); var concreteInheritanceFirstDerivedClass1 = ConcreteInheritanceFirstDerivedClass.NewObject(); ((IConcreteInheritancePersistentMixin)concreteInheritanceFirstDerivedClass1).PersistentProperty = "value 1"; var concreteInheritanceFirstDerivedClass2 = ConcreteInheritanceFirstDerivedClass.NewObject(); ((IConcreteInheritancePersistentMixin)concreteInheritanceFirstDerivedClass2).PersistentProperty = "value 2"; var concreteInheritanceSecondDerivedClass1 = ConcreteInheritanceSecondDerivedClass.NewObject(); ((IConcreteInheritancePersistentMixin)concreteInheritanceSecondDerivedClass1).PersistentProperty = "value 1"; var concreteInheritanceSecondDerivedClass2 = ConcreteInheritanceSecondDerivedClass.NewObject(); ((IConcreteInheritancePersistentMixin)concreteInheritanceSecondDerivedClass2).PersistentProperty = "value 2"; ClientTransaction.Current.Commit(); var queryWithConcreteTableInheritance = from obj in QueryFactory.CreateLinqQuery <ConcreteInheritanceBaseClass> () where (obj is ConcreteInheritanceFirstDerivedClass || obj is ConcreteInheritanceSecondDerivedClass) && (((IConcreteInheritancePersistentMixin)obj).PersistentProperty == "value 1") select obj; CheckQueryResult(queryWithConcreteTableInheritance, concreteInheritanceFirstDerivedClass1.ID, concreteInheritanceSecondDerivedClass1.ID); }
public void SingleInheritance_GetObject() { ObjectID firstDerivedClassObjectID; ObjectID secondDerivedClassObjectID; using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var firstDerivedClass = SingleInheritanceFirstDerivedClass.NewObject(); firstDerivedClassObjectID = firstDerivedClass.ID; var secondDerivedClass = SingleInheritanceSecondDerivedClass.NewObject(); secondDerivedClassObjectID = secondDerivedClass.ID; ClientTransaction.Current.Commit(); } using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { Assert.IsInstanceOf(typeof(SingleInheritanceFirstDerivedClass), LifetimeService.GetObject(ClientTransaction.Current, firstDerivedClassObjectID, false)); Assert.IsInstanceOf(typeof(SingleInheritanceSecondDerivedClass), LifetimeService.GetObject(ClientTransaction.Current, secondDerivedClassObjectID, false)); } }
public void SingleInheritance_QueryOverView() { using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var firstDerivedClass = SingleInheritanceFirstDerivedClass.NewObject(); var secondDerivedClass = SingleInheritanceSecondDerivedClass.NewObject(); firstDerivedClass.BaseProperty = "BasePropertyValue 1"; firstDerivedClass.FirstDerivedProperty = "FirstDerivedPropertyValue 1"; ((ISingleInheritancePersistentMixin)firstDerivedClass).PersistentProperty = "PersistentPropertyValue 1"; secondDerivedClass.BaseProperty = "BasePropertyValue 2"; secondDerivedClass.SecondDerivedProperty = "SecondDerivedPropertyValue 2"; ((ISingleInheritancePersistentMixin)secondDerivedClass).PersistentProperty = "PersistentPropertyValue 2"; ClientTransaction.Current.Commit(); } using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var query = new Query(new QueryDefinition("QueryOverUnionView", TestDomainStorageProviderDefinition, "SELECT * FROM [SingleInheritanceBaseClassView]", QueryType.Collection), new QueryParameterCollection()); var actualObjects = ClientTransaction.Current.QueryManager.GetCollection <SingleInheritanceBaseClass> (query); Assert.That(actualObjects.Count, Is.EqualTo(2)); var actualFirstDerivedClass = actualObjects.AsEnumerable().OfType <SingleInheritanceFirstDerivedClass> ().Single(); var actualSecondDerivedClass = actualObjects.AsEnumerable().OfType <SingleInheritanceSecondDerivedClass> ().Single(); Assert.That(actualFirstDerivedClass.BaseProperty, Is.EqualTo("BasePropertyValue 1")); Assert.That(actualFirstDerivedClass.FirstDerivedProperty, Is.EqualTo("FirstDerivedPropertyValue 1")); Assert.That(((ISingleInheritancePersistentMixin)actualFirstDerivedClass).PersistentProperty, Is.EqualTo("PersistentPropertyValue 1")); Assert.That(actualSecondDerivedClass.BaseProperty, Is.EqualTo("BasePropertyValue 2")); Assert.That(actualSecondDerivedClass.SecondDerivedProperty, Is.EqualTo("SecondDerivedPropertyValue 2")); Assert.That(((ISingleInheritancePersistentMixin)actualSecondDerivedClass).PersistentProperty, Is.EqualTo("PersistentPropertyValue 2")); } }