我已經具有三個layers.I使用的EntityFramework 6.1和代碼使用現有database.The三層第一遷移是一個應用程序在下面給出:啓用遷移不工作
1. Presententation層:ConceptuCodeFirstMigrationDemo 只需爲了簡單起見,控制檯應用程序
數據層語境下設和Initializer.The代碼如下給出:
namespace ConceptuCodeFirstMigrationDemo.Data.DataContext
{
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using ConceptuCodeFirstMigrationDemo.Domain;
public partial class ConceptuContext : DbContext,IDisposable
{
public ConceptuContext()
: base("name=ConceptuContext")
{
}
public virtual DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<User>()
.WithRequired(e => e.User)
.HasForeignKey(e => e.CreatedBy)
.WillCascadeOnDelete(false);
}
}
}
ConceptuInitializer.Cs
namespace ConceptuCodeFirstMigrationDemo.Data.DataContext
{
public class ConceptuInitializer: System.Data.Entity.CreateDatabaseIfNotExists<ConceptuContext>
{
}
}
的AppConfig:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<contexts>
<context type="ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuContext, ConceptuCodeFirstMigrationDemo.Data">
<databaseInitializer type="ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuInitializer, ConceptuCodeFirstMigrationDemo.Data" />
</context>
</contexts>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="ConceptuContext" connectionString="data source=AMITABHA-PC;initial catalog=Conceptu;user id=sa;password=lovediya;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
領域層:例如由用戶
實體類的寫一個新的類時,我嘗試使用,使遷移後啓用遷移 顯示 程序集中找不到任何上下文類型'ConceptuCod eFirstMigrationDemo」。
後我嘗試以下命令: ENABLE-遷移-ContextTypeName ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuContext
這表明以下錯誤 上下文類型 'ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuContext' 未找到在程序集'ConceptuCodeFirstMigrationDemo'中。
後我嘗試以下命令 啓用-遷移ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuContext
它顯示以下錯誤
啓用-遷移:位置參數不能被發現,接受參數' ConceptuCodeFirstMigrationDemo.Data.DataContext.Concept uContext'。 在行:1字符:18 +啓用-遷移< < < < ConceptuCodeFirstMigrationDemo.Data.DataContext.ConceptuContext + CategoryInfo:InvalidArgument:(:) [啓用-遷移],ParameterBindingException + FullyQualifiedErrorId:PositionalParameterNotFound,啓用的遷移
是位於不同項目中的三層'Presententation Layer','Data Layer'和'Domain Layer'嗎? –
是的,他們在不同的項目。 – Joydip