add-migration test
System.InvalidOperationException: 序列不包含任何匹配元素
在 System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
在 System.Data.Entity.Utilities.DbProviderManifestExtensions.GetStoreTypeFromName(DbProviderManifest providerManifest, String name)
在 System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(EdmProperty column, EntityType table, DbProviderManifest providerManifest, Boolean allowOverride, Boolean fillFromExistingConfiguration)
在 System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.<>c__DisplayClass1.<Configure>b__0(Tuple`2 pm)
在 System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable`1 ts, Action`1 action)
在 System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(IEnumerable`1 propertyMappings, DbProviderManifest providerManifest, Boolean allowOverride, Boolean fillFromExistingConfiguration)
在 System.Data.Entity.ModelConfiguration.Configuration.Types.StructuralTypeConfiguration.ConfigurePropertyMappings(IList`1 propertyMappings, DbProviderManifest providerManifest, Boolean allowOverride)
在 System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigurePropertyMappings(DbDatabaseMapping databaseMapping, EntityType entityType, DbProviderManifest providerManifest, Boolean allowOverride)
在 System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EntityType entityType, DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
在 System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
在 System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
在 System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
在 System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
在 System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
在 System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
在 System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized()
在 System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
在 System.Data.Entity.Utilities.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w)
在 System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action`1 writeXml)
在 System.Data.Entity.Utilities.DbContextExtensions.GetModel(DbContext context)
在 System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase)
在 System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
在 System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration)
在 System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()
在 System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
在 System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
在 System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
在 System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges)
在 System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
在 System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0()
在 System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
序列不包含任何匹配元素
请问各位这是什么原因?
检查一下:
例如:1.
public class Employee { [Key] public int EmployeeId { get; set; } public string Name { get; set; } [ForeignKey("ManagerId")] public Employee Manager { get; set; } public int ManagerId { get; set; } }
[ForeignKey("ManagerId")]
public Employee Manager { get; set; }
public int ManagerId { get; set; }
这个外键设置。
2.
[Column(TypeName="VARCHAR(254)")]
public string ColumnName { get; set; }
这样的定义,改成:
[MaxLength(254)] [Column(TypeName="VARCHAR")]
public string ColumnName { get; set; }
3.
modelBuilder.Entity<Category>() .HasKey(c => c.IdCategory ) .HasOptional(p => p.Children) .WithMany() .HasForeignKey(c => c.ChildrenId); 改成: modelBuilder.Entity<Category>() .HasKey(c => c.IdCategory ) .HasMany(p => p.Children) .WithOptional() .HasForeignKey(c => c.ChildrenId); .WithMany()换成.WithOptional()
再试试。
[Display(Name="费"),Column(TypeName="money")]中的money 写成了moeny