我尝试从作为数据访问层的控制台应用程序项目首先进行代码迁移。我通过几个不同的来源most recently this尝试过。我似乎不断达到相同的" Nullable对象必须有一个值。"错误。
以下是我正在使用的内容:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
}
}
}
},
"dependencies": {
"ePay.EmployeeRepository.Models": "1.0.0-*",
"Microsoft.EntityFrameworkCore": "1.0.1",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
"Microsoft.EntityFrameworkCore.SqlServer.Design": {
"version": "1.0.1",
"type": "build"
},
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
}
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
}
}
public class EmployeeRepositoryDbContext : DbContext
{
public DbSet<EmployeeDL> Employees { get; set; }
public DbSet<AgencyDL> Agencies { get; set; }
public EmployeeRepositoryDbContext(DbContextOptions<EmployeeRepositoryDbContext> options)
: base(options)
{ }
}
public class EmployeeRepositoryDbContextFactory : IDbContextFactory<EmployeeRepositoryDbContext>
{
public EmployeeRepositoryDbContext Create(DbContextFactoryOptions options)
{
var builder = new DbContextOptionsBuilder<EmployeeRepositoryDbContext>();
builder.UseSqlServer(@"Server=*;Database=*;user id=*;password=*;");
return new EmployeeRepositoryDbContext(builder.Options);
}
}
public static class EmployeeRepositoryDbContextExtensions
{
public static void AddEntityFramework(this IServiceCollection services, string connectionString)
{
services.AddDbContext<EmployeeRepositoryDbContext>(options =>
options.UseSqlServer(connectionString));
}
}
这是完整的堆栈跟踪:
System.InvalidOperationException: Nullable object must have a value.at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.DetachKeys(IEnumerable`1 keysToDetach)
at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.DetachProperties(IEnumerable`1 propertiesToDetach)
at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.Property(Property existingProperty, String propertyName, Type propertyType, PropertyInfo clrProperty, Nullable`1 configurationSource)
at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.Property(String propertyName, Type propertyType, PropertyInfo clrProperty, Nullable`1 configurationSource)
at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.Property(PropertyInfo clrProperty, ConfigurationSource configurationSource)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder, EntityType oldBaseType)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnBaseEntityTypeSet(InternalEntityTypeBuilder entityTypeBuilder, EntityType previousBaseType)
at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.HasBaseType(EntityType baseEntityType, ConfigurationSource configurationSource)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Internal.Model.AddEntityType(EntityType entityType, Boolean runConventions)
at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalModelBuilder.Entity(Type type, ConfigurationSource configurationSource, Boolean runConventions)
at Microsoft.EntityFrameworkCore.ModelBuilder.Entity(Type type)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.FindSets(ModelBuilder modelBuilder, DbContext context)
at Microsoft.EntityFrameworkCore.Infrastructure.Internal.RelationalModelSource.FindSets(ModelBuilder modelBuilder, DbContext context)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
at Microsoft.Extensions.DependencyInjection.ServiceProvider.ScopedCallSite.Invoke(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.TransientCallSite.Invoke(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite.Invoke(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.TransientCallSite.Invoke(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.Execute(CommonOptions commonOptions, String name, String outputDir, String context, String environment, Action`1 reporter)
at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.<>c__DisplayClass0_0.<Configure>b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
Nullable object must have a value.
非常感谢任何和所有帮助!