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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - InFuture

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

Visual Studio 2008 SP1: EntityDataSource Where Clause

This post in one of a series of blog posts about SP1 of Visual Studio 2008 and .Net Framework 3.5.

In the previous post about the EntityDataSource I've showed how to use it in a very basic way, which meant that I didn't customize the EntityDataSource at all. In this post I'll show how to filter the displayed entities by adding a where clause expressed by an Entity SQL statement.

EntityDataSource Where

Taking from where I finished in the last post, I now want to filter the customers by their city, according to the city that was selected in a listbox control. To so that:

1. Add a listbox control that contains items for filtering the list of entities. For example, if we want to filter customers by city, we will add a listbox similar to:

<asp:ListBox ID="list" runat="server" AutoPostBack="true">

    <asp:ListItem Text="Tel Aviv" Value="Tel Aviv" />

    <asp:ListItem Text="Haifa" Value="Haifa" />

</asp:ListBox>

2. Go to the property grid of the EntityDataSource and locate the Where property. In this property, write an Entity SQL statement that may have parameters that start with @, or use the Expression Editor to do this. For example: it.City == @city

EntityDataSource Where Bug Expression Editor

3. Using the Add Parameter button in the Expression Editor, add a new parameter with the same name as you used in the where clause, and choose the parameter source. You can choose to take the parameter value from a session value, from another control's value, and some other options. For this sample, choose Parameter Source = Control, and from the ControlID dropdown, select the listbox control ID.

EntityDataSource Where Parameter Source

Note: In the Beta of SP1 of Visual Studio 2008 and .Net Framework 3.5 there is a known bug that prevents you from using this Expression Editor and choose the parameter source, which will be fixed when we RTM. For now, after specifying the Where Expression, switch to the source view and add the parameters manually:

<asp:EntityDataSource ID="EntityDataSource" runat="server" ConnectionString="name=BankEntities"

  ContextTypeName="" DefaultContainerName="BankEntities" EnableDelete="True" EnableInsert="True"

  EnableUpdate="True" EntitySetName="Customers" Where="it.City == @city">

  <WhereParameters>

    <asp:ControlParameter Name="city" Type="String" ControlID="list" PropertyName="SelectedValue" />

  </WhereParameters>

</asp:EntityDataSource>

4. Run and browse to the page, and select one of the values in the listbox. The data shown in the gridview will be refreshed according to the where clause and the selected value of the listbox.

EntityDataSource Where ControlParameter

Enjoy!