Exemple #1
0
        public void ResolveIDPropertyViaForeignKey_WithFullObjectID_ResolvesToCompound()
        {
            var propertyDefinition      = CreatePropertyDefinitionAndAssociateWithClass(_classDefinition, "Customer", "Customer");
            var objectIDStorageProperty = ObjectIDStoragePropertyDefinitionObjectMother.Create(
                "CustomerID",
                "CustomerClassID",
                StorageTypeInformationObjectMother.CreateUniqueIdentifierStorageTypeInformation(),
                StorageTypeInformationObjectMother.CreateVarchar100StorageTypeInformation());

            var foreignKeyEndPointDefinition = new RelationEndPointDefinition(propertyDefinition, false);

            _rdbmsPersistenceModelProviderStub
            .Stub(stub => stub.GetStoragePropertyDefinition(foreignKeyEndPointDefinition.PropertyDefinition))
            .Return(objectIDStorageProperty);

            var originatingEntity = CreateEntityDefinition(typeof(Order), "o");

            var result = _storageSpecificExpressionResolver.ResolveIDPropertyViaForeignKey(originatingEntity, foreignKeyEndPointDefinition);

            var expected = Expression.New(
                MemberInfoFromExpressionUtility.GetConstructor(() => new ObjectID("classID", "value")),
                new[]
            {
                new NamedExpression("ClassID", originatingEntity.GetColumn(typeof(string), "CustomerClassID", false)),
                new NamedExpression("Value", Expression.Convert(originatingEntity.GetColumn(typeof(Guid), "CustomerID", false), typeof(object)))
            },
                new[] { typeof(ObjectID).GetProperty("ClassID"), typeof(ObjectID).GetProperty("Value") });

            SqlExpressionTreeComparer.CheckAreEqualTrees(expected, result);
        }
Exemple #2
0
        public override void SetUp()
        {
            base.SetUp();

            _factory = new SqlTableScriptElementFactory();

            var column1   = new ColumnDefinition("Column1", StorageTypeInformationObjectMother.CreateVarchar100StorageTypeInformation(false), false);
            var column2   = new ColumnDefinition("Column2", StorageTypeInformationObjectMother.CreateBitStorageTypeInformation(true), false);
            var property1 = new SimpleStoragePropertyDefinition(typeof(string), column1);
            var property2 = new SimpleStoragePropertyDefinition(typeof(bool), column2);

            var idColumn         = new ColumnDefinition("ID", StorageTypeInformationObjectMother.CreateUniqueIdentifierStorageTypeInformation(false), true);
            var classIDColumn    = new ColumnDefinition("ClassID", StorageTypeInformationObjectMother.CreateVarchar100StorageTypeInformation(true), false);
            var objectIDProperty = new ObjectIDStoragePropertyDefinition(
                new SimpleStoragePropertyDefinition(typeof(object), idColumn),
                new SimpleStoragePropertyDefinition(typeof(string), classIDColumn));
            var timestampColumn   = new ColumnDefinition("Timestamp", StorageTypeInformationObjectMother.CreateDateTimeStorageTypeInformation(true), false);
            var timestampProperty = new SimpleStoragePropertyDefinition(typeof(object), timestampColumn);

            _tableDefinitionWithoutPrimaryKeyConstraint = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                new EntityNameDefinition("SchemaName", "EntityName"),
                null,
                objectIDProperty,
                timestampProperty,
                property1);

            _tableDefinitionWithClusteredPrimaryKeyConstraint = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                new EntityNameDefinition("SchemaName", "EntityName"),
                null,
                objectIDProperty,
                timestampProperty,
                new[] { property1, property2 },
                new ITableConstraintDefinition[] { new PrimaryKeyConstraintDefinition("PKName", true, new[] { column1 }) });

            _tableDefinitionWithNonClusteredPrimaryKeyConstraint = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                new EntityNameDefinition(null, "EntityName"),
                null,
                objectIDProperty,
                timestampProperty,
                new[] { property1, property2 },
                new ITableConstraintDefinition[] { new PrimaryKeyConstraintDefinition("PKName", false, new[] { column1, column2 }) });
        }