예제 #1
0
        private void CheckKeyNotInUse(Key key)
        {
            var foreignKey = Model?.FindReferencingForeignKeys(key).FirstOrDefault();

            if (foreignKey != null)
            {
                throw new InvalidOperationException(Strings.KeyInUse(Property.Format(key.Properties), Name, foreignKey.DeclaringEntityType.Name));
            }
        }
예제 #2
0
 public virtual IEnumerable <ForeignKey> FindReferencingForeignKeys() => Model.FindReferencingForeignKeys(this);
예제 #3
0
        public void Can_get_referencing_foreign_keys()
        {
            var model = new Model();
            var entityType1 = model.AddEntityType(typeof(Customer));
            var entityType2 = model.AddEntityType(typeof(Order));
            var keyProperty = entityType1.AddProperty("Id", typeof(int));
            var fkProperty = entityType2.AddProperty("CustomerId", typeof(int?));
            var foreignKey = entityType2.GetOrAddForeignKey(fkProperty, entityType1.AddKey(keyProperty), entityType1);

            var referencingForeignKeys = model.FindReferencingForeignKeys(entityType1);

            Assert.Same(foreignKey, referencingForeignKeys.Single());
            Assert.Same(foreignKey, entityType1.FindReferencingForeignKeys().Single());
        }