第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

執(zhí)行代碼優(yōu)先遷移時無法在 Visual Studio 2017 中加載文件或程序集

執(zhí)行代碼優(yōu)先遷移時無法在 Visual Studio 2017 中加載文件或程序集

C#
哆啦的時光機 2021-09-19 16:01:11
在這里,我嘗試在 VS 2017 中開發(fā) .NetFrameworkCore 項目。我有一個包含兩個項目的解決方案類庫ASP .net 核心應(yīng)用程序我想創(chuàng)建可以使用enable-migrations和的遷移add-migration InitialCreate。在此之前,我在 startUp.cs 中配置了我的項目,如下所示:  public void ConfigureServices(IServiceCollection services)    {        // Add framework services.        services.AddMvc();        //======================================Setting ConnectionString to Database        services.AddDbContext<EfDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DbCon")));        //services.AddCors();        //======================API Level and Function Level        services.AddCors(action => action.AddPolicy("PolicyName", //============Adding Policy which was Created in the api             builder => builder.WithOrigins("http://localhost:4200") //Adding access the URL for giving access to the URL(s)            .WithMethods("Get", "Post", "Put", "Delete")// Adding access to the method(s) for the request from the 'URL'            .AllowAnyHeader()));//Adding access to any headers from the 'URL'    }這絕對沒問題。我喜歡這樣的 EfDbContext:    public EfDbContext(DbContextOptions options) : base(options)    {    }    public DbSet<utblPhoto> utblPhotos { get; set; }    protected override void OnModelCreating(ModelBuilder modelBuilder)    {        EfConfiguration(modelBuilder);    }    private static void EfConfiguration(ModelBuilder modelBuilder)    {       //**************************************Table Mapping        modelBuilder.Entity<utblPhoto>().ToTable("utblPhoto");    }對于我使用過的關(guān)鍵注釋System.ComponentModel.DataAnnotations這是因為我還沒有找到System.Data.Entity.Core. 編譯解決方案工作正常,但在創(chuàng)建遷移時我有錯誤說明Could not load file or assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.我想,有兩種可能我正在使用 ASP.net 核心應(yīng)用程序,其中我有 ClassLibrary 項目,因此我遇到了上述錯誤遷移時,它正在搜索System.Data.Entity.CoreEF6我應(yīng)該如何使用Code First Migrations.
查看完整描述

1 回答

?
Smart貓小萌

TA貢獻1911條經(jīng)驗 獲得超7個贊

您的代碼中似乎沒有任何問題。我建議您使用 EF 6 中的 Fluent API 配置在EfConfiguration. 試試這個。


private static void EfConfiguration(ModelBuilder modelBuilder)

{

   modelBuilder.Entity<utblPhoto>().ToTable("utblPhoto");

   modelBuilder.Entity<utblPhoto>().HasKey(t=> new {t.PhotoId});

}

完整指南可在此處找到。希望這對你有幫助。


查看完整回答
反對 回復(fù) 2021-09-19
  • 1 回答
  • 0 關(guān)注
  • 218 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號