(MVC) MVC (2018)

Project for refactoring ODBC access to MySQL up to EF6 Code First with MySQL.

As a freelancer I receive ancient project that was written in 2004 year with ODBC-access to MySQL on style below:



A customer want to upgrade function of this software and rebuild it to modern technology. Before my refactoring code style was in left screen below, and target of refactoring is to code style on right screen below.



Also project was have some problems. For example, modern version of MySQL is 8, but inexpensive hosting support only MySQL of 5 version.



This difference between version of SQL server create many difficulties, because Oracle has renamed some property in ODBC connector, rot example "tx_isolation was deprecated in MySQL 5.7 and MySQL 8 changed the name of the system variable from tx_isolation to transaction_isolation". This issue cause to inoperability Oracle ODBC driver with different version of MySQL.



Also Oracle programmers has renamed package MySql.Data.Entity to MySql.Data.EntityFramework. In other side Microsoft programmer use in Server Explorer for access to MySQL old version on Oracle .NET connector. This issue induce some difficulties in searching right way to provide correctly working Visual Studio and Entity Framework. SO, I have wrote this video with exactly right way to provide full functionality of Visual Studio and EF6.




So, this is my machine.config files from video.


 148:    <runtime>
 149:      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
 150:        <dependentAssembly xmlns="urn:schemas-microsoft-com:asm.v1">
 151:          <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
 152:          <bindingRedirect oldVersion="0.0.0.0-8.0.15.0" newVersion="8.0.15.0" />
 153:        </dependentAssembly>
 154:        <dependentAssembly xmlns="urn:schemas-microsoft-com:asm.v1">
 155:          <assemblyIdentity name="MySql.Data.Entity" publicKeyToken="c5687fc88969c44d" culture="neutral" />
 156:          <bindingRedirect oldVersion="0.0.0.0-8.0.15.0" newVersion="8.0.15.0" />
 157:        </dependentAssembly>
 158:        <dependentAssembly xmlns="urn:schemas-microsoft-com:asm.v1">
 159:          <assemblyIdentity name="MySql.Web" publicKeyToken="c5687fc88969c44d" culture="neutral" />
 160:          <bindingRedirect oldVersion="0.0.0.0-8.0.15.0" newVersion="8.0.15.0" />
 161:        </dependentAssembly>
 162:      </assemblyBinding>
 163:    </runtime>
 164:    <connectionStrings>
 165:      <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
 166:      <add name="LocalMySqlServer" connectionString="" />
 167:    </connectionStrings>
 168:    <system.data>
 169:      <DbProviderFactories>
 170:        <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
 171:        <add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
 172:        <remove invariant="MySql.Data.MySqlClient" />
 173:        <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=8.0.15.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
 174:      </DbProviderFactories>
 175:    </system.data>

And this is my packages.config.


   1:  <?xml version="1.0" encoding="utf-8"?>
   2:  <packages>
   3:    <package id="EntityFramework" version="6.2.0" targetFramework="net472" />
   4:    <package id="Google.Protobuf" version="3.5.1" targetFramework="net472" />
   5:    <package id="MySql.Data" version="8.0.15" targetFramework="net472" />
   6:    <package id="MySql.Data.EntityFramework" version="8.0.15" targetFramework="net472" />
   7:  </packages>

And this is my application.config file.


   1:  <?xml version="1.0" encoding="utf-8"?>
   2:  <configuration>
   3:    <configSections>
   4:      <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
   5:      <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
   6:    </configSections>
   7:    <startup>
   8:      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
   9:    </startup>
  10:    <entityFramework>
  11:      <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  12:      <providers>
  13:        <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  14:        <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.15.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
  15:        </provider>
  16:      </providers>
  17:    </entityFramework>
  18:    <connectionStrings>
  19:      <add name="LocalDB1" connectionString="server=localhost;user id=gb_bravo;database=gb_bravo;password=xxxxxxxxx;persistsecurityinfo=True" providerName="MySql.Data.MySqlClient" />
  20:    </connectionStrings>
  21:  </configuration>

In my Environment I also receive an error message, what solve by restart VS and recompile project.

This is external reference list of my project from .PRJ file.


  50:    <ItemGroup>
  51:      <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
  52:        <HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
  53:      </Reference>
  54:      <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
  55:        <HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
  56:      </Reference>
  57:      <Reference Include="Google.Protobuf, Version=3.5.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL">
  58:        <HintPath>..\packages\Google.Protobuf.3.5.1\lib\net45\Google.Protobuf.dll</HintPath>
  59:      </Reference>
  60:      <Reference Include="Microsoft.CSharp" />
  61:      <Reference Include="MySql.Data, Version=8.0.15.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
  62:        <HintPath>..\packages\MySql.Data.8.0.15\lib\net452\MySql.Data.dll</HintPath>
  63:      </Reference>
  64:      <Reference Include="MySql.Data.EntityFramework, Version=8.0.15.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
  65:        <HintPath>..\packages\MySql.Data.EntityFramework.8.0.15\lib\net452\MySql.Data.EntityFramework.dll</HintPath>
  66:      </Reference>
  67:      <Reference Include="System" />
  68:      <Reference Include="System.ComponentModel" />
  69:      <Reference Include="System.ComponentModel.DataAnnotations" />
  70:      <Reference Include="System.Configuration" />
  71:      <Reference Include="System.Configuration.Install" />
  72:      <Reference Include="System.Data" />
  73:      <Reference Include="System.Deployment" />
  74:      <Reference Include="System.Drawing" />
  75:      <Reference Include="System.Drawing.Design" />
  76:      <Reference Include="System.Management" />
  77:      <Reference Include="System.Runtime.Serialization" />
  78:      <Reference Include="System.Security" />
  79:      <Reference Include="System.Transactions" />
  80:      <Reference Include="System.Xml" />
  81:      <Reference Include="System.Core" />
  82:      <Reference Include="System.Xml.Linq" />
  83:      <Reference Include="System.Data.DataSetExtensions" />
  84:      <Reference Include="System.Net.Http" />
  85:    </ItemGroup>
  86:    <ItemGroup>
  87:      <Import Include="Microsoft.VisualBasic" />
  88:      <Import Include="System" />
  89:      <Import Include="System.Collections" />
  90:      <Import Include="System.Collections.Generic" />
  91:      <Import Include="System.Data" />
  92:      <Import Include="System.Diagnostics" />
  93:      <Import Include="System.Linq" />
  94:      <Import Include="System.Xml.Linq" />
  95:      <Import Include="System.Threading.Tasks" />
  96:    </ItemGroup>

This is version of my MySQL tools for Visual Studio.



And this is useful documentation for various version of MySQL connectors https://dev.mysql.com/doc/connector-net/en/connector-net-versions.html

Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: //www.vb-net.com/MySQL-and-EF6/index.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>