EF6使用Mysql进行数据库操作

375 阅读1分钟

背景说明

使用VS2022开发.net framework 4.0 桌面应用程序;

安装依赖包

  • EntityFramework 6.4.4
  • MySql.Data 6.8.8
  • MySql.Data.Entities 6.8.3

配置文件

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<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.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
	</configSections>
	<entityFramework>
		<providers>
			<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
		</providers>
	</entityFramework>
	<system.data>
		<DbProviderFactories>
			<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
		</DbProviderFactories>
	</system.data>
	<connectionStrings>
		<add name="PwDb_MySql" connectionString="Server=127.0.0.1;Port=3306; Database=dbname;uid=root; password=123456" providerName="MySql.Data.MySqlClient"/>
	</connectionStrings>
	<appSettings>
		<add key="dbType" value="MySql"/>
	</appSettings>
	<runtime>
		<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
			<dependentAssembly>
				<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral"/>
				<bindingRedirect oldVersion="0.0.0.0-6.8.8.0" newVersion="6.8.8.0"/>
			</dependentAssembly>
		</assemblyBinding>
	</runtime>
	<startup>
		<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
	</startup>
</configuration>