如何创建JetEntityFrameworkProvider.JetConnection并使用现有的Edmx元数据?

时间:2019-05-15 21:32:19

标签: c# entity-framework-6

我使用Entity Framework 6作为ORM来映射现有的SQL Server数据库。我想使我的软件不仅限于SQL Server,而且还可以连接到Access数据库。我使用JetEntityFrameworkProvider作为解决方案,但由于所有关系都在Ed​​mx中,因此似乎无法使用。 有什么方法可以让JetEntityFrameworkProvider在使用ADO.Net生成的相同模型的同时工作?


            System.Data.OleDb.OleDbConnectionStringBuilder oleDbConnectionStringBuilder = new System.Data.OleDb.OleDbConnectionStringBuilder();
            oleDbConnectionStringBuilder.Provider = "Microsoft.ACE.OLEDB.12.0";
            oleDbConnectionStringBuilder.DataSource = ServerName;
            oleDbConnectionStringBuilder["Jet OLEDB:Database Password"] = Password;

            JetEntityFrameworkProvider.JetConnection.DUAL = JetEntityFrameworkProvider.JetConnection.DUALForAccdb;
            System.Data.Common.DbConnection connection = new JetEntityFrameworkProvider.JetConnection();
            var MetaData = string.Format("metadata=res://{0}/CMSModel.csdl|res://{0}/CMSModel.ssdl|res://{0}/CMSModel.msl;", typeof(CMSEntities).Assembly.FullName);
            var x = MetaData + "provider connection string=\"" + oleDbConnectionStringBuilder.ToString() + "\"";

            connection.ConnectionString = MetaData + "provider connection string=\"" + oleDbConnectionStringBuilder.ToString() + "\"";

0 个答案:

没有答案