我正在开发一个mvc4 asp.net Web应用程序。我想添加一个迁移,但显示错误,我不知道如何解决它。 这是该类的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace POCOs
{
public class Consultant
{
public int Id { get; set; }
public string Nom { get; set; }
public string Prenom { get; set; }
public string RefCommercial { get; set; }
public string DateNaissance { get; set; }
public int CIN { get; set; }
public string Fonction { get; set; }
public string Tel { get; set; }
public string Experience { get; set; }
public string Email { get; set; }
public HttpPostedFileBase CV { get; set; }
public ICollection<Prestation> prestations { get; set; }
public Consultant()
{
prestations = new HashSet<Prestation>();
}
}
}
这是我想要添加迁移时遇到的错误:
Add-Migration
cmdlet Add-Migration at command pipeline position 1
Supply values for the following parameters:
Name: cv
System.ArgumentNullException: Value cannot be null.
Parameter name: key
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at System.Data.Entity.ModelConfiguration.Configuration.Mapping.SortedEntityTypeIndex.Add(EdmEntitySet entitySet, EdmEntityType entityType)
at System.Data.Entity.ModelConfiguration.Configuration.Mapping.EntityMappingService.Analyze()
at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.LazyInternalContext.get_CodeFirstModel()
at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
at System.Data.Entity.Migrations.Extensions.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w)
at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(Action`1 writeXml)
at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(DbContext context)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Value cannot be null.
Parameter name: key
任何帮助?
答案 0 :(得分:7)
答案 1 :(得分:4)
我在EF7工作。我也遇到了这个错误,并且不知道是什么导致了它。
最后我追溯到我做了一些名称空间重构的事实,所以我的模型类在快照类中的名称空间不同(快照类使用字符串来限定类!)
我删除了快照文件并进行了虚拟迁移以更新快照。然后我删除了虚拟迁移,之后我的迁移再次正常工作。
答案 2 :(得分:1)
HttpPostedFileBase是System.Web命名空间中的内置类。它不会被EF识别。您可以创建一个包装器类型来保存您需要的数据。