Reputation: 2880
I am using ASP.NET 5 and Entity Framework 6 (precisely 6.1.3), following this link. Tried every different solution like
<dependentAssembly>
Update-Package
-reinstall EntityFramework
I get error here
[DbConfigurationType(typeof(CodeConfig))]
public class MyContext : DbContext
{
public MyContext()
: base("DefaultConnection") <-- error here
{
}
}
But still couldn't resolve this error, any helpful links would be appreciated
Could not load file or assembly 'EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.":"EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
Stack Trace
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Data.Entity.Utilities.TypeExtensions.CreateInstance[T](Type type, Func`2 exceptionFactory)
at System.Data.Entity.Utilities.TypeExtensions.CreateInstance[T](Type type, Func`3 typeMessageFactory, Func`2 exceptionFactory)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.<.ctor>b__1()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.GetConfiguration()
at System.Data.Entity.Infrastructure.DependencyResolution.InternalConfiguration.get_Instance()
at System.Data.Entity.DbConfiguration.get_DependencyResolver()
at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model)
at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
at myproject.data.myprojectContext..ctor() in D:\Projects\Personal\myproject\myproject.data\myprojectContext.cs:line 12
at myproject.data.Infrastructure.DatabaseFactory.Get() in D:\Projects\Personal\myproject\myproject.data\Infrastructure\DatabaseFactory.cs:line 9
at myproject.data.Repository`1.get_DataContext() in D:\Projects\Personal\myproject\myproject.data\Repository.cs:line 28
at myproject.data.Repository`1..ctor(IDatabaseFactory databaseFactory) in D:\Projects\Personal\myproject\myproject.data\Repository.cs:line 21
at myproject.data.Repository.ProfileRepository..ctor(IDatabaseFactory databaseFactory) in D:\Projects\Personal\myproject\myproject.data\Repository\ProfileRepository.cs:line 9
Web.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="...." />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
Upvotes: 7
Views: 2539
Reputation: 453
The parameter of base (DbContext constructor) can be a nameOrConnectionString
. See DbContext(string).
So you should add name=
to the parameter string.
[DbConfigurationType(typeof(CodeConfig))]
public class MyContext : DbContext
{
public MyContext()
: base("name=DefaultConnection")
{
}
}
See also this example: Derived context
Upvotes: 0
Reputation: 195
First check which version EF you are using. Check the your version. If you want to upgrade your version you can manage EF upgrade from NuGet.
Go to your Project solution - > 'Manage NuGet packet for Solution', click 'Manage' on 'Entity Framework'.
Now, Check your app.config . Maybe here wrong version number. The name="entityFramework" should have the correct version number.
Other then this, you should try installing the nuget package for EntityFramework.SqlServer by using following command in package manager console.
Install-Package EntityFramework.SqlServer -Version 7.0.0-beta6 -Pre
Upvotes: 0