Could not load file or assembly 'System.ComponentModel.DataAnnotations' in Visual Studio 2017 while doing Code First Migrations c# entity-framework-6 entity-framework-core


I'm here trying to grow. VS 2017's NetFrameworkCore project. I have two projects for a solution.

  1. School Library
  2. Core Application for ASP.NET

I wanted to develop a migration that I could utilise.enable-migrations and add-migration InitialCreate . Prior to that, I set up my project in startUp.cs as follows:

    public void ConfigureServices(IServiceCollection services)
        // Add framework services.
        //======================================Setting ConnectionString to Database
        services.AddDbContext<EfDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DbCon")));
        //======================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'


Which is completely OK. This is how my EfDbContext looks:

    public EfDbContext(DbContextOptions options) : base(options)
    public DbSet<utblPhoto> utblPhotos { get; set; }
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    private static void EfConfiguration(ModelBuilder modelBuilder)
       //**************************************Table Mapping 

My utblPhoto the following class is in the ClassLibrary Project:

public class utblPhoto
    public int PhotoId { get; set; }
    public string PhotoTitle { get; set; }
    public string PhotoDescription { get; set; }
    public string PhotoUrl { get; set; }
    public DateTime CreatedDate { get; set; }
    public DateTime UpdatedOn { get; set; }
    public string UpdatedBy { get; set; }

I used for key annotationSystem.ComponentModel.DataAnnotations Because I have not discoveredSystem.Data.Entity.Core . The solution compiles without issue, however when I try to create the migration, I get an error sayingCould not load file or assembly 'System.ComponentModel.DataAnnotations, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

I suppose there are two options.

  1. I have a ClassLibrary Project in my ASP.NET core application, which is why I am seeing the above problem.
  2. In its migration, it looks forSystem.Data.Entity.Core for EF6

How can I use SQL Server to migrate my EfDbClasses?Code First Migrations .

7/4/2018 5:44:10 AM

Accepted Answer

7/4/2018 6:11:27 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow