我正在学习ASP.NET。我现在接触到EntityDataSource控件,使用的是EF6。我注意到这个控件和EF6之间存在一些问题和冲突,但是根据EntityDataSource的最新更新,这个问题已经得到解决了。你可以查看以下链接获取更多信息:http://blogs.msdn.com/b/webdev/archive/2014/02/28/announcing-the-release-of-dynamic-data-provider-and-entitydatasource-control-for-entity-framework-6.aspx
我尝试按照上述链接进行操作。首先我创建了一个.edmx模型文件。
然后我通过NuGet安装了新版本的EntityDataSource控件。
我添加了两个EntityDataSource控件,并将其中一个的前缀改为ef。因此我现在有两个控件,一个是旧版本的,另一个是升级后的新版本。
当我点击旧版本的控件时,弹出了配置弹框,并能够打开“Configure Data Source”界面。但是当我点击新版本的控件时,却没有弹框。那么,我该如何配置数据源呢?这是什么问题?
以下是我的Web.config配置文件:
然后我通过NuGet安装了新版本的EntityDataSource控件。
我添加了两个EntityDataSource控件,并将其中一个的前缀改为ef。因此我现在有两个控件,一个是旧版本的,另一个是升级后的新版本。
当我点击旧版本的控件时,弹出了配置弹框,并能够打开“Configure Data Source”界面。但是当我点击新版本的控件时,却没有弹框。那么,我该如何配置数据源呢?这是什么问题?
以下是我的Web.config配置文件:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5"/>
<pages>
<controls>
<add tagPrefix="ef" assembly="Microsoft.AspNet.EntityDataSource" namespace="Microsoft.AspNet.EntityDataSource"/>
</controls>
</pages>
</system.web>
<connectionStrings>
<add name="SampleDbEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=OMER-HP\SQLEXPRESS2014OK;initial catalog=SampleDb;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"/>
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication6.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ef:EntityDataSource ID="EntityDataSourceNew" runat="server">
</ef:EntityDataSource>
<br />
<asp:EntityDataSource ID="EntityDataSourceOld" runat="server">
</asp:EntityDataSource>
</div>
</form>
</body>
</html>