我第一次尝试使用MySQL实体框架。我使用https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html
中的代码进行示例编码。我正在使用代码(没有变化)
。我的App.config文件是这样的 -
<configuration>
<connectionStrings>
<add name="MyContext" providerName="MySql.Data.MySqlClient"
connectionString="server=localhost;port=3306;database=act_saga;uid=root;password=ABcdEf32!"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<entityFramework>
<codeConfiguration Type="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6"/>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<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.10.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
</DbProviderFactories>
</system.data>
</configuration>
我使用的是MySQL Server 5.7,Entity Framework 6.1.3,MySQL.Data 6.10.4,MySQL.Data.Entity 6.10.4和MySQL Connector / Net 6.10.4。
在调试时,我找到了行
using (Parking contextDB = new Parking(connection, false))
抛出异常
"Inheritance security rules violated by type:
'MySql.Data.Entity.MySqlEFConfiguration'. Derived types must either match the
security accessibility of the base type or be less accessible. The stack
trace is as follows -
at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule,
IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
at System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module,
IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule
decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType
attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes,
Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.Attribute.GetCustomAttributes(MemberInfo element, Type type, Boolean inherit)
at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[T](MemberInfo element, Boolean inherit)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationFinder.TryFindConfigurationType(Assembly assemblyHint, Type contextTypeHint, IEnumerable`1 typesToSearch)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForAssembly(Assembly assemblyHint, Type contextTypeHint)
at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType)
at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model)
at System.Data.Entity.DbContext..ctor(DbConnection existingConnection, Boolean contextOwnsConnection)
at MySQLWithEF.Parking..ctor(DbConnection existingConnection, Boolean contextOwnsConnection) in C:\Users\vsinghthakur\Desktop\Knowledge\MySQLWithEF\MySQLWithEF\Parking.cs:line 26
at MySQLWithEF.Program.Main(String[] args) in C:\Users\vsinghthakur\Desktop\Knowledge\MySQLWithEF\MySQLWithEF\Program.cs:line 21
我通过更改配置,改变连接字符串的位置,卸载和重新安装软件包,尝试了很多,但没有任何效果。
我错过了什么?它是MySQL站点的示例代码。