با استفاده از آموزش دوره Asp.Net Core 2 ی پروژه ای ایجاد کردم حالا که نوبت به ساخت دیتابیس توسط Migration میشه خطای زیر نمایش داده میشود:
target project 'MyCms.Web' doesn't match your migrations assembly 'MyCms.DataLayer'. Either change your target project or change your migrations assembly.
Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("MyCms.Web")). By default, the migrations assembly is the assembly containing the DbContext.
Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project.
این قطعه کد مربوط به appsettings.json می باشد:
{ "Logging": { "LogLevel": { "Default": "Warning" } }, "AllowedHosts": "*", "ConnectionStrings": { "MyCmsDbContext": "Data Source=.;Initial Catalog =MyCmsCore_DB;Integrated Security=True" } }
و اینم قطعه کد مربوط به Startup می باشد:
public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure<CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddDbContext<MyCmsDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("MyCmsDbContext")) ); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvcWithDefaultRoute(); //app.UseMvc(routes => //{ // routes.MapRoute( // name: "default", // template: "{controller=Home}/{action=Index}/{id?}"); //}); } }
نسخه ای که پروژه باهاش شروع کردم Net Core 2.1 هست...
لطفا راهنمایی کنید.
Migration های شما کجا قرار دارند باید روی همان پروژه Migration اضافه کنید.
به پروژه MyCms.web
Migration اضافه کردم .
باید آن را روی MyCms.DataLayer اعمال کنید جایی که DbContext قرار دارد.
ممنون مهندس
اوکی شد.
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)