예제 #1
0
        public virtual bool CompatibleWithModel(
            InternalContext internalContext,
            ModelHashCalculator modelHashCalculator,
            bool throwIfNoMetadata,
            DatabaseExistenceState existenceState = DatabaseExistenceState.Unknown)
        {
            if (internalContext.CodeFirstModel == null)
            {
                if (throwIfNoMetadata)
                {
                    throw Error.Database_NonCodeFirstCompatibilityCheck();
                }
                return(true);
            }
            VersionedModel model = internalContext.QueryForModel(existenceState);

            if (model != null)
            {
                return(internalContext.ModelMatches(model));
            }
            string a = internalContext.QueryForModelHash();

            if (a != null)
            {
                return(string.Equals(a, modelHashCalculator.Calculate(internalContext.CodeFirstModel), StringComparison.Ordinal));
            }
            if (throwIfNoMetadata)
            {
                throw Error.Database_NoDatabaseMetadata();
            }
            return(true);
        }
        public virtual bool CompatibleWithModel(
            InternalContext internalContext, ModelHashCalculator modelHashCalculator,
            bool throwIfNoMetadata, DatabaseExistenceState existenceState = DatabaseExistenceState.Unknown)
        {
            DebugCheck.NotNull(internalContext);
            DebugCheck.NotNull(modelHashCalculator);

            if (internalContext.CodeFirstModel == null)
            {
                if (throwIfNoMetadata)
                {
                    throw Error.Database_NonCodeFirstCompatibilityCheck();
                }
                return(true);
            }

            var model = internalContext.QueryForModel(existenceState);

            if (model != null)
            {
                return(internalContext.ModelMatches(model));
            }

            // Migrations history was not found in the database so fall back to doing a model hash compare
            // to deal with databases created using EF 4.1 and 4.2.
            var databaseModelHash = internalContext.QueryForModelHash();

            if (databaseModelHash == null)
            {
                if (throwIfNoMetadata)
                {
                    throw Error.Database_NoDatabaseMetadata();
                }
                return(true);
            }

            return(String.Equals(
                       databaseModelHash, modelHashCalculator.Calculate(internalContext.CodeFirstModel),
                       StringComparison.Ordinal));
        }
        public virtual bool CompatibleWithModel(
            InternalContext internalContext, ModelHashCalculator modelHashCalculator,
            bool throwIfNoMetadata, DatabaseExistenceState existenceState = DatabaseExistenceState.Unknown)
        {
            DebugCheck.NotNull(internalContext);
            DebugCheck.NotNull(modelHashCalculator);

            if (internalContext.CodeFirstModel == null)
            {
                if (throwIfNoMetadata)
                {
                    throw Error.Database_NonCodeFirstCompatibilityCheck();
                }
                return true;
            }

            var model = internalContext.QueryForModel(existenceState);
            if (model != null)
            {
                return internalContext.ModelMatches(model);
            }

            // Migrations history was not found in the database so fall back to doing a model hash compare
            // to deal with databases created using EF 4.1 and 4.2.
            var databaseModelHash = internalContext.QueryForModelHash();
            if (databaseModelHash == null)
            {
                if (throwIfNoMetadata)
                {
                    throw Error.Database_NoDatabaseMetadata();
                }
                return true;
            }

            return String.Equals(
                databaseModelHash, modelHashCalculator.Calculate(internalContext.CodeFirstModel),
                StringComparison.Ordinal);
        }