Ao tentar gerar a tabela pelo migration esto tendo o seguinte erro
PM> Add-Migration criaUsuario
System.NullReferenceException: Object reference not set to an instance of an object.
at Entity.EntidadesContext.OnConfiguring(DbContextOptionsBuilder optionsBuilder) in C:\Users\Gustavo\Documents\Visual Studio 2015\Projects\Entity\Entity\EntidadesContext.cs:line 18
at Microsoft.Data.Entity.DbContext.InitializeServices(IServiceProvider serviceProvider, DbContextOptions options)
at Microsoft.Data.Entity.DbContext.<>c__DisplayClass12_0.<Initialize>b__0()
at Microsoft.Data.Entity.Internal.LazyRef`1.get_Value()
at Microsoft.Data.Entity.DbContext.get_ServiceProvider()
at Microsoft.Data.Entity.DbContext.Microsoft.Data.Entity.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
at Microsoft.Data.Entity.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
at Microsoft.Data.Entity.Design.DbContextOperations.CreateContext(String contextType)
at Microsoft.Data.Entity.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.Data.Entity.Design.OperationExecutor.<AddMigrationImpl>d__7.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.Execute(Action action)
Object reference not set to an instance of an object.
Minha classe Usuario.cs esta assim
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entity.Entidades
{
public class Usuario
{
public int ID { get; set; }
public string Nome { get; set; }
public string Senha { get; set; }
}
}
Minha classe EntidadesContext.cs esta assim
using Entity.Entidades;
using Microsoft.Data.Entity;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entity
{
class EntidadesContext : DbContext
{
public DbSet<Usuario> Usuarios { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string stringConexao = ConfigurationManager.ConnectionStrings["lojaConnectionStringTeste "].ConnectionString;
optionsBuilder.UseSqlServer(stringConexao);
base.OnConfiguring(optionsBuilder);
}
}
}
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="lojaConnectionStringTeste" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="C:\Users\Gustavo\Documents\Visual Studio 2015\Projects\Entity\loja.mdf";Integrated Security=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
</configuration>