切换实体模型以连接到 DB2 需要进行两项更改。根据您所拥有的版本,这显然可能会改变。.edmx 更改:
<!-- SQL SERVER <Schema Namespace="Models.myDb2Model.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">-->
<Schema Namespace="Models.myDb2Model.Store" Alias="Self" Provider="IBM.Data.DB2" ProviderManifestToken="DB2, 09.01.0005, 0, 0" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
这是 web.config 更改:
<!-- SQL SERVER<add name="db2Connection"
connectionString="metadata=res://*/Models.db2Entities.csdl|res://*/Models.db2Entities.ssdl|res://*/Models.db2Entities.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=mySqlServerDb;integrated security=True;multipleactiveresultsets=True;App=EntityFramework""
providerName="System.Data.EntityClient" /> -->
<add name="db2Connection"
connectionString="metadata=res://*/Models.db2Entities.csdl|res://*/Models.db2Entities.ssdl|res://*/Models.db2Entities.msl;provider=IBM.Data.DB2;provider connection string="Database=myDb2Db;User ID=myUserId;Password=MyPassword;Server=myServerName:myPort;DBName=myDbName;ConcurrentAccessResolution=Currentlycommitted;CurrentPackageSet=myCurrentPackageSet""
providerName="System.Data.EntityClient" />
编辑:显然您的机器需要设置为连接到 DB2,为 VS 安装适当的客户端和数据库插件。