如何在mvc3项目中使用引用的dll中的模型

|| 我有一个具有它自己的模型和数据库连接字符串的类库。独立运行,一切正常,从数据库中检索数据没有问题。这个库的想法是创建一个dll并在另一个应用程序中引用它。 就我而言,我有一个MVC3 Web应用程序,它具有自己的模型和连接字符串。我引用了类库,添加了第二个连接字符串,并构建了整个应用程序。但是,当我运行应用程序并在引用的库上实际调用方法时,我收到一个EntitySqlException,说“ \'\'MyTable \'在当前作用域或上下文中无法解析。请确保所有引用的变量都在作用域内,已加载必需的模式,并正确引用了名称空间。在转义的标识符附近,第1行,第1列,\“ 我确保将所引用库的模型文件也复制到mvc项目的bin目录中,并且我的web.config如下所示:
<configSections>
<section name=\"DefaultArchitecture\" type=\"DefaultArchitectureConfiguration\"/>
</configSections> 

<DefaultArchitecture defaultContainerName=\"defaultContainer\" connectionStringName=\"defaultContainer\"/>

<connectionStrings>
<add name=\"defaultContainer\" connectionString=\"metadata=res://*/MvcModel.csdl|res://*/MvcModel.ssdl|res://*/MvcModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=cloudaddress;Initial Catalog=main catalog;User ID=user;Password=pass;Encrypt=true;Trusted_Connection=false;trustServerCertificate=true&quot;\" providerName=\"System.Data.EntityClient\" />
<add name=\"secondContainer\" 
     connectionString=\"metadata=~\\bin\\libmodel.csdl|
                                ~\\bin\\libmodel.ssdl|
                                ~\\bin\\libmodel.msl;
                       provider=System.Data.SqlClient;
                       provider connection string=&quot;
                       data source=cloudaddress;
                       initial catalog=othercatalog;
                       persist security info=True;
                       user id=user;
                       password=pass;
                       multipleactiveresultsets=True;
                       App=EntityFramework&quot;\" 
      providerName=\"System.Data.EntityClient\" />
如果我将defaultcontainername更改为secondcontainer ...,它对于引用的库工作正常,但是对于defaultcontainer当然不再可用。 问题是...如何在我的mvc项目中使用具有自己的模型(和自己的数据库)的引用的类库,而又不能解决其中一个实体的问题,如何同时使用这两个模型。 希望我的问题清楚。如果没有,请告诉我,以便我提供更多信息。     
已邀请:
最终,事实证明这是一个上下文问题。调用类库时,我仍然使用错误的上下文。我通过实现一个idisposable并在创建库的服务类时切换到正确的上下文并切换回废弃的方法来修复它。     

要回复问题请先登录注册