惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 聂微东
F
Fortinet All Blogs
H
Help Net Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
DataBreaches.Net
MyScale Blog
MyScale Blog
B
Blog
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
IT之家
IT之家
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
博客园_首页
L
LangChain Blog
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky

博客园 - InFuture

变成百万富翁的二十五种方法 今天终于测试解决了WCF传递大数据量的问题 关于工作流设计方面的一些经验总结 Telnet客户端 字符串表达式求值(转) silverlight DataGrid模板列的动态生成 关于事件处理的完整框架Event,delegate,event args,无图有真相。 关于树形结构父类查子类,子类查父类的方法 最近准备整理一下手头资料,开发一个工作流和表单管理系统 今天装好了window 7 Silverlight 客户端如何访问WCF 如何让用户控件占满全部页面,silverlight用户控件开发问题 wpf 数据绑定有关讲解 ASP.NET 3.5 Extensions: Dynamic Data Web Site 要點整理(转载) 免费的微软OneCare防病毒软件 Visual Studio 2008 SP1: EntityDataSource Where Clause(转载) 今天装了VS2008 Sp1!真是非常激动!(VS2008 sp1下载地址) ASP.NET里的支架:Dynamic Data Support(转载) VS2008的黑色皮肤
Visual Studio 2008 SP1: EntityDataSource for ASP.Net (转...
InFuture · 2008-08-22 · via 博客园 - InFuture

Visual Studio 2008 SP1: EntityDataSource for ASP.Net

EntityDataSource is a new DataSource control for ASP.Net (just like ObjectDataSource and SQLDataSource and more recent - LinqDataSource) which makes declaratively binding ASP.NET UI controls to Entity Data Models very easy.

In this post I will build a simple web application that uses EntityDataSource in order to demo how it is being used.

1. Create a simple Web Application, and create an initial GridView on it.

<body>

    <form id="form1" runat="server">

    <h1>

        Using the EntityDataSource</h1>

    <asp:GridView runat="server" ID="GridView" />

    </form>

</body>

2. Create a new ADO.Net Entity Data Model. Add a new ADO.Net Entity Data Model item to the project, and generate a model from an existing database. For this sample I am using the Bank DB Schema, but you can use any other schema as well.

Visual Studio 2008 SP1 Beta EntityDataSource

3. If the EntityDataSource is not shown in the Toolbox under the Data category - Add it. Right click the toolbox and select the Choose Items... option.

Visual Studio 2008 SP1 Beta EntityDataSource

In the Choose Toolbox Item dialog, set the filter to Entity and check the EntityDataSource component.

4. Add a reference to System.Web.Entity.dll. The EntityDataSource component is part of a new assembly in SP1 called System.Web.Entity.dll, and its designer support components can be found in System.Web.Entity.Design.dll.

5. Bind the grid to the EntityDataSource. Switch to design view and select the gridview to display the smart tag. In the Choose Data Source drop down select the option <new data source...>

Visual Studio 2008 SP1 Beta Entity DataSource

This will start the Data Source Configuration Wizard. Select the Entity Data Source and provide a meaningful name.

Visual Studio 2008 SP1 Beta EntityDataSource

Select the name of the connection to use and the name of the container.

Visual Studio 2008 SP1 Beta EntityDataSource

Select the name of the EntitySet you want to display its entities and the columns you would like to display. If the EntitySet contains a hierarchy of entity types, you can filter the type you want.

Visual Studio 2008 SP1 Beta EntityDataSource

When we click the "Finish" button, VS 2008 will declare a <asp:EntityDataSource> within the .aspx page, and update the <asp:gridview> to point to it.

Visual Studio 2008 SP1 Beta EntityDataSource

And in the source view it looks like:

<asp:GridView runat="server" ID="GridView" " DataKeyNames="CustomerID"

    DataSourceID="EntityDataSource" >

    <Columns>

        ...

    </Columns>

</asp:GridView>

<asp:EntityDataSource ID="EntityDataSource" runat="server"

    ConnectionString="name=BankEntities" ContextTypeName=""

    DefaultContainerName="BankEntities" EntitySetName="Customers">

</asp:EntityDataSource>

6. If we now run this application, we can see the details in the grid.

Visual Studio 2008 SP1 Beta EntityDataSource

In this post I had a step by step guide on how to use the EntityDataSource in a very basic way. In the next post I'll show how to filter entities using a where clause.

Enjoy!