使用EF4作为比我的MVC项目一个单独的项目编译器错误 [英] Compiler error using EF4 as a separate project than my MVC project

查看:89
本文介绍了使用EF4作为比我的MVC项目一个单独的项目编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图遵循普遍的共识是,最好把自己的域对象比MVC项目一个单独的项目,但我得到以下编译器错误:


  

指定的命名连接或者未在配置中发现,不打算与EntityClient提供者使用,或不是有效的。


  
  

源文件:C:\\用户\\凯文\\文档\\ Visual Studio 2010的\\项目\\ HandiGamer \\ HandiGamer.Domain \\ \\实体线HGDomainModel.Designer.cs:44


  42号线:///初始化使用应用程序配置文件的HGEntities一节中的连接字符串新HGEntities对象。
第43行:///< /总结>
第44行:公共HGEntities():基地(NAME = HGEntities,HGEntities)
第45行:{
46号线:this.ContextOptions.LazyLoadingEnabled = TRUE;

我有点困惑,因为HGEntities的的出现在实体的app.config文件:

 <?XML版本=1.0编码=UTF-8&GT?;
<结构>
  <&是connectionStrings GT;
    <添加名称=HGEntities connectionString=\"metadata=res://*/Entities.HGDomainModel.csdl|res://*/Entities.HGDomainModel.ssdl|res://*/Entities.HGDomainModel.msl;provider=System.Data.SqlClient;provider连接字符串=安培; QUOT;数据源= \\ SQLEX $ P $干燥综合征。AttachDbFilename = | DataDirectory目录| \\ HandiGamer.mdf;集成安全=真;用户实例=真; MultipleActiveResultSets =真放; QUOT;的providerName =系统。 Data.EntityClient/>
  < /&是connectionStrings GT;
< /结构>

我是否需要连接添加到我的MVC的Web.Config什么?


解决方案

是的,你需要将它添加到你的MVC Web.Config文件。
搜索结果
既然你在的地方有一个A​​SP.Net MVC项目,连接字符串必须在你的MVC项目的Web.config present其中运行时将期待找到它。基本上任何连接字符串应该是你的可执行项目的配置文件(即,其中净线程由CLR启动)。所以,只要复制和整个连接字符串粘贴到您的web.conig,大功告成!

I'm trying to follow the general consensus that it's best to put one's domain objects in a separate project than their MVC project, but am getting the following compiler error:

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

Source File: C:\Users\Kevin\documents\visual studio 2010\Projects\HandiGamer\HandiGamer.Domain\Entities\HGDomainModel.Designer.cs Line: 44

Line 42:         /// Initializes a new HGEntities object using the connection string found in the 'HGEntities' section of the application configuration file.
Line 43:         /// </summary>
Line 44:         public HGEntities() : base("name=HGEntities", "HGEntities")
Line 45:         {
Line 46:             this.ContextOptions.LazyLoadingEnabled = true;

I'm a bit confused, as HGEntities is there in the entity's App.Config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="HGEntities" connectionString="metadata=res://*/Entities.HGDomainModel.csdl|res://*/Entities.HGDomainModel.ssdl|res://*/Entities.HGDomainModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HandiGamer.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

Do I need to add the connection to my MVC Web.Config or something?

解决方案

Yes you need to add it to your MVC Web.Config file.

Since you have an ASP.Net MVC project in place, the connection string must be present in the web.config of your MVC project where the runtime will be looking to find it. Basically any connection string should be in the config file of your executable project (i.e. where the .Net threads started from by CLR). So just copy and paste the whole connection string into your web.conig and you're done!

这篇关于使用EF4作为比我的MVC项目一个单独的项目编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆