我是ASP .NET MVC的新手。我尝试使用实体框架,但它失败了,因为它没有找到EF。我搜索一个解决方案,并在另一篇文章中说我必须更改版本。我做了,但没有成功。
的Web.config:
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.1.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<!--<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-SportsStore.WebUI-20150201211232;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-SportsStore.WebUI-20150201211232.mdf" />-->
<!--<add name="EFDbContext" providerName="System.Data.SqlClient" connectionString="Data Source=(localDb)\v11.0;Initial Catalog=SportsStore;Integrated Security=True" />-->
<add name="EFDbContext" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-SportsStore.WebUI-20150201211232;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-SportsStore.WebUI-20150201211232.mdf" />
</connectionStrings>
这是浏览器的错误。
&#39; /&#39;中的服务器错误应用
Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileLoadException: Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source Error:
Line 11: public class EFProductRepository : IProductsRepository
Line 12: {
Line 13: private EFDbContext context = new EFDbContext();
Line 14:
Line 15: public IQueryable<Product> Products {
Source File: c:\Users\ruben\Documents\Visual Studio 2012\Projects\SportsStore\SportsStore.Domain\Concrete\EFProductRepository.cs Line: 13
Assembly Load Trace: The following information can be helpful to determine why the assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' could not be loaded.
=== Pre-bind state information ===
LOG: User = rubenPC\ruben
LOG: DisplayName = EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
(Fully-specified)
LOG: Appbase = file:///C:/Users/ruben/Documents/Visual Studio 2012/Projects/SportsStore/SportsStore.WebUI/
LOG: Initial PrivatePath = C:\Users\ruben\Documents\Visual Studio 2012\Projects\SportsStore\SportsStore.WebUI\bin
Calling assembly : SportsStore.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\ruben\Documents\Visual Studio 2012\Projects\SportsStore\SportsStore.WebUI\web.config
LOG: Using host configuration file: C:\Users\ruben\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
LOG: Attempting download of new URL file:///C:/Users/ruben/AppData/Local/Temp/Temporary ASP.NET Files/vs/400ee849/decd1b79/EntityFramework.DLL.
LOG: Attempting download of new URL file:///C:/Users/ruben/AppData/Local/Temp/Temporary ASP.NET Files/vs/400ee849/decd1b79/EntityFramework/EntityFramework.DLL.
LOG: Attempting download of new URL file:///C:/Users/ruben/Documents/Visual Studio 2012/Projects/SportsStore/SportsStore.WebUI/bin/EntityFramework.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Stack Trace:
[FileLoadException: Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
SportsStore.Domain.Concrete.EFProductRepository..ctor() in c:\Users\ruben\Documents\Visual Studio 2012\Projects\SportsStore\SportsStore.Domain\Concrete\EFProductRepository.cs:13
DynamicInjectorf437813e479848489e7ebb4769e5ef53(Object[] ) +70
Ninject.Activation.Providers.StandardProvider.Create(IContext context) +884
Ninject.Activation.Context.ResolveInternal(Object scope) +218
Ninject.Activation.Context.Resolve() +277
Ninject.<>c__DisplayClass15.<Resolve>b__f(IBinding binding) +86
System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +145
System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +4078797
Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent) +169
Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) +747
Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) +269
Ninject.Activation.Providers.<>c__DisplayClass4.<Create>b__2(ITarget target) +69
System.Linq.WhereSelectArrayIterator`2.MoveNext() +66
System.Linq.Buffer`1..ctor(IEnumerable`1 source) +216
System.Linq.Enumerable.ToArray(IEnumerable`1 source) +77
Ninject.Activation.Providers.StandardProvider.Create(IContext context) +847
Ninject.Activation.Context.ResolveInternal(Object scope) +218
Ninject.Activation.Context.Resolve() +277
Ninject.<>c__DisplayClass15.<Resolve>b__f(IBinding binding) +86
System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +145
System.Linq.Enumerable.Single(IEnumerable`1 source) +191
Ninject.ResolutionExtensions.Get(IResolutionRoot root, Type service, IParameter[] parameters) +70
SportsStore.WebUI.Infrastructure.NinjectControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) in c:\Users\ruben\Documents\Visual Studio 2012\Projects\SportsStore\SportsStore.WebUI\Infrastructure\NinjectControllerFactory.cs:27
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +197
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +49
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237
这就是break的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;
namespace SportsStore.Domain.Concrete
{
public class EFProductRepository : IProductsRepository
{
private EFDbContext context = new EFDbContext();
public IQueryable<Product> Products {
get { return context.Products; }
}
}
}
EFDbContext.cs类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SportsStore.Domain.Entities;
using System.Data.Entity;
namespace SportsStore.Domain.Concrete
{
public class EFDbContext : DbContext
{
public DbSet<Product> Products { get; set; }
}
}
答案 0 :(得分:3)
打开
Toos > Nuget Package Manager > Package Manager Console
然后运行
install-package entityframework -version 6.0.0.0