Open bobdcode opened 8 years ago
@Dixin , could you take a look here please?
Ha-ha, 8 years later... You can skip adding function while running migrations:
// DatabaseInitializer
internal static readonly AsyncLocal<bool> DbMigrator = new AsyncLocal<bool>();
DbMigrator.Value = true;
var migrator = new DbMigrator(Configuration);
var migrations = migrator.GetPendingMigrations().ToList();
DbMigrator.Value = false;
I added an aggregate function: [Function(FunctionType.AggregateFunction, "BitwiseOr", Schema = "dbo")] public static int BitwiseOr(IEnumerable value)
{
throw new NotImplementedException();
}
to my context via:
modelBuilder.Conventions.Add(new FunctionConvention());
It works correctly, however, I'm not able to perform database migrations due to the following error:
PM> update-database Specify the '-Verbose' flag to view the SQL statements being applied to the target database. No pending explicit migrations. System.Data.Entity.Core.MetadataException: Schema specified is not valid. Errors: (0,0) : error 0034: Unknown namespace or alias (collection[SqlServer). at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.ThrowOnNonWarningErrors() at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerableb b()
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>cDisplayClass2.<.ctor>b0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Schema specified is not valid. Errors:
(0,0) : error 0034: Unknown namespace or alias (collection[SqlServer).
1 xmlReaders, IEnumerable
1 sourceFilePaths) at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader..ctor(IEnumerable1 xmlReaders, IEnumerable
1 sourceFilePaths, Boolean throwOnError, IDbDependencyResolver resolver) at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Init(IEnumerable1 xmlReaders, IEnumerable
1 filePaths, Boolean throwOnError, IDbDependencyResolver resolver, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerInvariantName, String& providerManifestToken, Memoizer2& cachedCTypeFunction) at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection..ctor(IEnumerable
1 xmlReaders) at System.Data.Entity.Utilities.XDocumentExtensions.GetStorageMappingItemCollection(XDocument model, DbProviderInfo& providerInfo) at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(XDocument sourceModel, XDocument targetModel, Lazy1 modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator, String sourceModelVersion, String targetModelVersion) at System.Data.Entity.Migrations.DbMigrator.IsModelOutOfDate(XDocument model, DbMigration lastMigration) at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable
1 pendingMigrations, String targetMigrationId, String lastMigrationId) at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId) at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration) at System.Data.Entity.Migrations.DbMigrator.<>cDisplayClassc.