Esempio n. 1
0
        public void Setting_ClrType_throws_when_referenced()
        {
            var entityType = new Model().AddEntityType(typeof(object));
            var principalProperty = entityType.AddProperty("Kake");
            var key = entityType.AddKey(principalProperty);
            var dependentProperty = entityType.AddProperty("Alaska");
            entityType.AddForeignKey(dependentProperty, key, entityType);

            Assert.Equal(CoreStrings.PropertyClrTypeCannotBeChangedWhenReferenced("Kake", "{'Alaska'}", "object"),
                Assert.Throws<InvalidOperationException>(() =>
                    principalProperty.ClrType = typeof(int)).Message);
            Assert.Equal(typeof(string), ((IProperty)principalProperty).ClrType);
        }
        private ForeignKey CreateSelfRefFK()
        {
            var entityType = new Model().AddEntityType(typeof(SelfRef));
            var pk = entityType.GetOrSetPrimaryKey(entityType.GetOrAddProperty("Id", typeof(int)));
            var fkProp = entityType.GetOrAddProperty("SelfRefId", typeof(int?));

            var fk = entityType.AddForeignKey(new[] { fkProp }, pk);
            fk.IsUnique = true;
            entityType.AddNavigation("SelfRefPrincipal", fk, pointsToPrincipal: true);
            entityType.AddNavigation("SelfRefDependent", fk, pointsToPrincipal: false);
            return fk;
        }
        private ForeignKey CreateOneToManyFK()
        {
            var principalEntityType = new Model().AddEntityType(typeof(OneToManyPrincipal));
            var pk = principalEntityType.GetOrSetPrimaryKey(principalEntityType.GetOrAddProperty("Id", typeof(int)));

            var dependentEntityType = new Model().AddEntityType(typeof(OneToManyDependent));
            var fkProp = dependentEntityType.GetOrAddProperty("Id", typeof(int));
            return dependentEntityType.AddForeignKey(new[] { fkProp }, pk);
        }