How can I alter the Entity Framework database schema (mysql database)?

c# connection database entity-framework mysql


In a project, I use EntityFramework to establish a connection to a MySQL database. Devart Dot.connect is the service provider.

The user must provide connection parameters during runtime for this program to connect to a database. Of course, the name of the MySQL database is included.

I built and stored the custom connexion parameters using the EntityConnectionStringBuiler and EntityConnection classes.

The issue is that, even with these specified settings, the program always connects to the database specified during EntityModel construction in Visual Studio. It is really odd that the custom connexion parameters are appropriately utilized while debugging and examining the status of the ObjectContext. It aggravates me greatly! Any ideas?

8/20/2009 3:45:25 PM

Accepted Answer

I worked on this topic for a day before realizing that the model.edmx file was the source of the problem.

Each EntitySet has a line in this file. A schema property exists on each EntitySet element. This property is assigned to the corresponding table structure in the case of SQL Server:

EntitySet Name="annee_civile" EntityType="openemisModel.Store.annee_civile" store:Type="Tables" Schema="mydatabase" />

If you provide the name of the schema while building your own EntityConnection, it seems that there is a conflict and that ultimately, even if you supplied another schema in the connection parameters, the schema described in the edmx file will be utilized.

Simply deleting the schema name from the edmx file will solve the problem. THIS WORKS FOR MYSQL, however connecting to a SQL server is probably not the case.

EntitySet Name="annee_civile" EntityType="openemisModel.Store.annee_civile" store:Type="Tables" Schema="" />

Invoking the EntityConnectionStringBuilder:

string providedString = "User Id=xxxx;Password=xxx;Host=xxxx;Database=anydatabasename"; EntityConnectionStringBuilder entityConnBuilder = new EntityConnectionStringBuilder(); entityConnBuilder.Provider = "Devart.Data.MySql"; entityConnBuilder.Metadata = @"res:///OpenEmisModel.csdl|res:///OpenEmisModel.ssdl|res://*/OpenEmisModel.msl"; entityConnBuilder.ProviderConnectionString = providedString;

The object context using the EntityConnection:

EntityConnection entityConnexionEmis = new EntityConnection(entityConnBuilder.ConnectionString);

objectcontextEntities testingContext = new objectcontextEntities(entityConnexionEmis);

Now, the program may establish a connection to any database name.

Hope this was useful.

8/20/2009 4:11:17 PM

Popular Answer

mention the dll The project contains Devart.Data.MySql.Entity.EF6.dll.

Add the following anywhere during program startup and before database operations happen:

var config = MySqlEntityProviderConfig.Instance;
config.Workarounds.IgnoreSchemaName = true;

You must use this as a reference:

using Devart.Data.MySql.Entity.Configuration;

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow