"how to change the database - schema used by entity framework (mysql database)?" Code Answer


after spending one day on this issue, i finally came to understand that the problem was coming from the model.edmx file.

in this file, you have one line per entityset. on each entityset element there is an attribute called schema. in case of sql server this attribute is set to the related table schema :

entityset name="annee_civile" entitytype="openemismodel.store.annee_civile" store:type="tables" schema="mydatabase" />

if you provide the name of the schema when constructiong you own entityconnection, it seem that there is a conflict and that finally, the schema defined in the edmx file will be used even if you specified another one in the connection parameters.

the solution is simply to remove the name of the schema in the edmx file. this works for mysql, probably not when connecting to a sql server.

entityset name="annee_civile" entitytype="openemismodel.store.annee_civile" store:type="tables" schema="" />

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 entityconnection and the object context using it:

entityconnection entityconnexionemis = new entityconnection(entityconnbuilder.connectionstring);

objectcontextentities testingcontext = new objectcontextentities(entityconnexionemis);

the software is now able to connect to any database name.

hope this helps.

By brady gaster on May 23 2022

Answers related to “how to change the database - schema used by entity framework (mysql database)?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.