我在项目中使用EntityFramework连接到Mysql数据库.提供者是Devart Dot.connect.
此应用程序需要使用用户在运行时给出的连接参数连接到数据库.这当然包括Mysql数据库名称.
我使用EntityConnectionStringBuiler和EntityConnection类来构建和存储自定义连接参数.
问题是即使使用这样的给定参数,应用程序也总是连接到使用visual studio向导设计EntityModel时命名的数据库.非常奇怪的是,当调试和检查ObjectContext的状态时,自定义连接参数被正确使用......这让我很生气!!!!! 任何线索?
我在尝试将对象添加到Entity Framework中的对象上下文时遇到问题.
这是代码:
//related object ids are retrieved from another context.
//since I thought the problem could be linked to object loaded in this context, I tried to
//close it and start on a fresh object context...
int idetab = currentEtab.Id;
long idnivcycle = selectedNivcycle.id_nivcycle;
long idanscol = AnneeScolaireEnCours.id_annee_scolaire;
//and this context is closed
context.Dispose();
//This is the new object context
objectcontextEntities ctest = new objectcontextEntities();
//from where I retrieve all the objects I want to link to the object …
Run Code Online (Sandbox Code Playgroud)