c# - Connection string in Database First using EF doesn't work correctly -


i made model via ef when trying execute query got error:

code generated using t4 templates database first , model first development may not work correctly if used in code first mode. continue using database first or model first ensure entity framework connection string specified in config file of executing application. use these classes, generated database first or model first, code first add additional configuration using attributes or dbmodelbuilder api , remove code throws exception.

i added model references mvc project , added connection string mvc project same error .

<connectionstrings>  <add name="educationdbentities" connectionstring="data source=.;      initial catalog=educationdb;user id=sa;password=ehsanakbar"      providername="system.data.sqlclient" /> </connectionstrings> 

i exception line :

  protected override void onmodelcreating(dbmodelbuilder modelbuilder)     {         throw new unintentionalcodefirstexception();     } 

this web config

<?xml version="1.0" encoding="utf-8"?>          <configuration>   <configsections>  <!-- 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=5.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false" />   </configsections> <connectionstrings>   <add name="educationdbentities" connectionstring="data source=.;initial catalog=educationdb;user id=sa;password=ehsanakbar"     providername="system.data.sqlclient" />   </connectionstrings>   <appsettings>     <add key="webpages:version" value="2.0.0.0" />     <add key="webpages:enabled" value="false" />     <add key="preserveloginurl" value="true" />     <add key="clientvalidationenabled" value="true" />     <add key="unobtrusivejavascriptenabled" value="true" />   </appsettings>   <system.web>     <compilation debug="true" targetframework="4.5" />     <httpruntime targetframework="4.5" />     <authentication mode="forms">       <forms loginurl="~/account/login" timeout="2880" />     </authentication>     <pages>       <namespaces>         <add namespace="system.web.helpers" />         <add namespace="system.web.mvc" />         <add namespace="system.web.mvc.ajax" />         <add namespace="system.web.mvc.html" />         <add namespace="system.web.optimization" />         <add namespace="system.web.routing" />         <add namespace="system.web.webpages" />       </namespaces>     </pages>   </system.web>   <system.webserver>     <validation validateintegratedmodeconfiguration="false" />     <handlers>       <remove name="extensionlessurlhandler-isapi-4.0_32bit" />       <remove name="extensionlessurlhandler-isapi-4.0_64bit" />       <remove name="extensionlessurlhandler-integrated-4.0" />       <add name="extensionlessurlhandler-isapi-4.0_32bit" path="*." verb="get,head,post,debug,put,delete,patch,options" modules="isapimodule" scriptprocessor="%windir%\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll" precondition="classicmode,runtimeversionv4.0,bitness32" responsebufferlimit="0" />       <add name="extensionlessurlhandler-isapi-4.0_64bit" path="*." verb="get,head,post,debug,put,delete,patch,options" modules="isapimodule" scriptprocessor="%windir%\microsoft.net\framework64\v4.0.30319\aspnet_isapi.dll" precondition="classicmode,runtimeversionv4.0,bitness64" responsebufferlimit="0" />       <add name="extensionlessurlhandler-integrated-4.0" path="*." verb="get,head,post,debug,put,delete,patch,options" type="system.web.handlers.transferrequesthandler" precondition="integratedmode,runtimeversionv4.0" />     </handlers>   </system.webserver>   <runtime>     <assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1">       <dependentassembly>         <assemblyidentity name="system.web.helpers" publickeytoken="31bf3856ad364e35" />         <bindingredirect oldversion="1.0.0.0-2.0.0.0" newversion="2.0.0.0" />       </dependentassembly>       <dependentassembly>         <assemblyidentity name="system.web.mvc" publickeytoken="31bf3856ad364e35" />         <bindingredirect oldversion="1.0.0.0-4.0.0.0" newversion="4.0.0.0" />       </dependentassembly>       <dependentassembly>         <assemblyidentity name="system.web.webpages" publickeytoken="31bf3856ad364e35" />         <bindingredirect oldversion="1.0.0.0-2.0.0.0" newversion="2.0.0.0" />       </dependentassembly>     </assemblybinding>   </runtime>   <entityframework>     <defaultconnectionfactory type="system.data.entity.infrastructure.localdbconnectionfactory, entityframework">       <parameters>         <parameter value="v11.0" />       </parameters>     </defaultconnectionfactory>   </entityframework> </configuration> 

this because you're trying use code first style connection string model/db first ef conceptual model.

if ef model has been generated db first, need specify different model aspects in connection string msl, ssdl , csdl files.

your connection string should this: "metadata=res:///entityframework.model1.csdl|res:///entityframework.model1.ssdl|res://*/entityframework.model1.msl;provider=mysql.data.mysqlclient;provider connection string="server=localhost;user id=myuserid;password=12345678;database=databasename""

this msdn article has section on need connection string model / db first:

https://msdn.microsoft.com/en-us/data/jj592674


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -