EF4.0連接SQL2000
一、建立一個空的Web運用程式
二、添加新建項目,選擇ADO.NET實體數據模型,改名為MyModel.edmx,
三、選擇空模型,完成
四、將MyModel.edmx以記事本的形式打開,並將用(http://www.skonet.com/uploadedFiles/Code/BaseEntityModel.edmx.xml )xml文件內容替換。並Ctrl+F把所有%DB_NAME% 替换成MyModel,共6处替换,替换完成后保存关闭该页,不关闭后面可能会出问题。
五、在项目中新建一个配置文件web.config,把以下配置节复制到web.config,
<connectionStrings>
<add name="%DB_NAME%Entities" connectionString="metadata=res://*/%DB_NAME%.csdl|res://*/%DB_NAME%.ssdl|res://*/%DB_NAME%.msl;provider=System.Data.SqlClient;providerconnection string="Data Source=%DB_HOST_NAME%;InitialCatalog=%DB_NAME%;Persist Security Info=True;UserID=%DB_USER%;Password=%DB_USER_PWD%;MultipleActiveResultSets=False"" providerName="System.Data.EntityClient" />
</connectionStrings>
六、把配置中的所有%DB_NAME%替换成MyModel,共5处替换,修改%DB_HOST_NAME%为你的数据库实例名。
七.Initial Catalog=%DB_NAME% 这里的%DB_NAME% 改成你要连接的库的名稱。
八、雙擊直接打開MyModel.edmx計設視圖模式打開,右擊選擇從數據庫更新模型。
九、同樣支持添加代碼生成項
整個項目就是這樣的
XML文件
<edmx:Edmxxmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx"Version="2.0">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schemaxmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator"xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl"Namespace="%DB_NAME%Model.Store" Alias="Self"Provider="System.Data.SqlClient"ProviderManifestToken="2000">
<EntityContainerName="%DB_NAME%ModelStoreContainer"></EntityContainer>
</Schema>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schemaxmlns="http://schemas.microsoft.com/ado/2008/09/edm"Namespace="%DB_NAME%Model" Alias="Self">
<EntityContainerxmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration"xmlns:b="http://schemas.microsoft.com/ado/2009/02/edm/annotation"Name="%DB_NAME%Entities" a:TypeAccess="Public"b:LazyLoadingEnabled="true"></EntityContainer>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mappingxmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs"Space="C-S">
<EntityContainerMappingStorageEntityContainer="%DB_NAME%ModelStoreContainer"CdmEntityContainer="%DB_NAME%Entities"></EntityContainerMapping>
</Mapping>
</edmx:Mappings>
</edmx:Runtime>
<!--
EF Designer content (DO NO2015/9/2t EDITMANUALLY BELOW HERE)
-->
<edmx:Designer>
<edmx:Connection>
<DesignerInfoPropertySetxmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
<DesignerPropertyName="MetadataArtifactProcessing"Value="EmbedInOutputAssembly"/>
</DesignerInfoPropertySet>
</edmx:Connection>
<edmx:Options>
<DesignerInfoPropertySetxmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
<DesignerPropertyName="ValidateOnBuild" Value="true"/>
<DesignerPropertyName="EnablePluralization" Value="True"/>
<DesignerPropertyName="IncludeForeignKeysInModel" Value="True"/>
</DesignerInfoPropertySet>
</edmx:Options>
<!-- Diagram content (shape and connectorpositions) -->
<edmx:Diagrams></edmx:Diagrams>
</edmx:Designer>
</edmx:Edmx>