asp.net数据动态曲线_将ASP.NET动态数据置于上下文中

asp.net数据动态曲线

asp.net数据动态曲线

There's a lot of folks excited about ASP.NET MVC as an option for creating ASP.NET websites. As I say in my ASP.NET MVC talks, however, I figure about 5% of people creating ASP.NET sites will care about ASP.NET MVC. I say that for a number of reasons. ASP.NET MVC is a big paradigm shift. It enables the developer to make a more testable site, to have absolute control over their markup, and to separate concerns in order to keep their code DRY (don't repeat yourself). However, MVC is not yet the ideal solution, in my opinion, for really data- and forms-heavy sites. Creating an data grid with editing in place with sorting, movable columns and all that coolness is hard in MVC as someone needs to manage all that state for you and there's some underlying infrastructure that's not there.

许多人都对ASP.NET MVC作为创建ASP.NET网站的一种选择感到兴奋。 正如我在ASP.NET MVC对话中所说的那样,我认为大约有5%的创建ASP.NET站点的人会关心ASP.NET MVC。 我说这是出于多种原因。 ASP.NET MVC是一个巨大的范式转变。 它使开发人员可以制作一个更具可测试性的网站,对其标记有绝对的控制权,并可以将关注点分开,以使他们的代码保持干燥(不要重复您自己)。 然而,MVC还不是理想的解决方案,在我看来,对于真正的数据和形式重的网站。 在MVC中很难创建具有排序,可移动列和所有这些功能的编辑的数据网格,因为有人需要为您管理所有状态,而底层基础结构还不存在。

So, What about the other 95% of developers? Certainly WebForms isn't going away, and it is a proven solution for line of business apps. Personally, I'll probably use some kind of hybrid as I have in the past at other jobs. DasBlog doesn't use MVC (yet) but it's templating system is MVC-like and it lives side-by-side with WebForms. Basically, there's a lot of WebForms developers out there just trying to get data up into a Grid or Edit view and also keep it DRY.

那么,其他95%的开发人员呢? 当然,WebForms不会消失,它是一系列业务应用程序的可靠解决方案。 就个人而言,我可能会像过去在其他工作中一样使用某种混合动力。 DasBlog尚未使用MVC,但其模板系统类似于MVC,并且与WebForms并存。 基本上,有很多WebForms开发人员只是试图将数据收集到Grid或Edit视图中,并使其保持DRY状态

You'll probably stumble onto information around ASP.NET Dynamic in your wanderings and I wanted to give you some information to put Dynamic Data's pending release into ASP.NET's larger context.

您可能会无所适从地发现有关ASP.NET Dynamic的信息,而我想为您提供一些信息,以将Dynamic Data的待发布版本放入ASP.NET的较大上下文中。

什么是ASP.NET动态数据? (What is ASP.NET Dynamic Data?)

Here's the Preview Drop of Dynamic Data for download. It'll be released later this year in a future Service Pack for .NET Framework 3.5. This is a pre-release build that's updated since the relatively quiet preview release last December.

这是要下载的动态数据预览滴。 它将于今年晚些时候在将来的.NET Framework 3.5 Service Pack中发布。 这是一个预发行版本,自去年12月相对安静的预览版本以来已更新。

Fundamentally, Dynamic data is new controls for DetailsView, FormView, GridView, or ListView controls along with a lot of meta-infrastructure classes to make it possible. The design uses convention over configuration in a number of places, and this marks, IMHO, the recognition of a simpler way to do things.

从根本上讲,动态数据是DetailsViewFormViewGridViewListView控件的新控件,以及许多使其变得可行的元基础结构类。 该设计在许多地方都采用了约定而不是配置,这标志着恕我直言,这是对简化工作方式的认可。

If you can point at one thing in Dynamic Data and say, "that's it!",  it'd be DynamicControl. it's a control that takes metadata from your Database model (LINQ to SQL or LINQ to Entities in v1, other POCOs (Plain Old CLR Objects) or ORM's possibly in v.Next) and selects from a FieldTemplateUserControl.

如果您可以指向动态数据中的件事并说“就是这样!”,那就是DynamicControl。 它是采用元数据从数据库模型控制(LINQ to SQL或LINQ到实体在V1,其他POCO S(普通老式CLR对象)或ORM的可能是在v.Next),并选择从FieldTemplateUserControl。

Stated differently, if you've got a field in a dozen places that should show Phone Numbers, you probably want a Textbox, some validators, maybe a MaskedEditControl, or perhaps some 3rd party controls. You think about it as a Phone Number. if you decide to change that control, you want to change it for the whole application. You want to keep it DRY (Don't Repeat Yourself). Currently, unless you had the discipline to create a PhoneNumberUserControl, you'd have to do "monkey work" and go find all the instances of that field and keep them up to date. You'll be repeating yourself all over with data that should exist in one place, like the length of the field in the database, gets copied into possibly dozens of places, validators, controls, etc.

换句话说,如果您在十几个地方都有一个应显示电话号码的字段,则可能需要一个文本框,一些验证器,一个MaskedEditControl或一些第三方控件。 您将其视为电话号码。 如果您决定更改该控件,则需要针对整个应用程序进行更改。 您想使其保持干燥(不要重复自己)。 当前,除非您有纪律来创建PhoneNumberUserControl,否则您必须做“猴子工作”并查找该字段的所有实例并保持最新。 您将在一处应该存在的数据(例如数据库中字段的长度)重复一遍,将其复制到可能数十个位置,验证器,控件等中。

Here's a comment that my friend Peter Blum left on ScottGu's Blog. It actually was Peter, not the Product Team, who helped me "grok" Dynamic Data a few weeks ago. We spent a few hours on the phone talking and it finally popped for me.

这是我的朋友Peter BlumScottGu的Blog上留下的评论。 实际上,是彼得而不是产品团队在几周前帮助我“获得”了动态数据。 我们花了几个小时在电话上交谈,终于为我弹出。

I have been working with Dynamic Data for over a month and am very excited about it. I wanted promote an aspect of Dynamic Data that will be used in many other situations than the application Scott showed.

我已经与Dynamic Data合作了一个多月,对此感到非常兴奋。 我想宣传动态数据的一个方面,该方面将在Scott展示的应用程序之外的许多其他情况下使用。

Dynamic Data introduces a new web control called DynamicControl. It can be used in FormView and ListView controls to provide a UI based on database-level schema. When using GridView and DetailsView, you add a DynamicField, which is a replacement for the BoundField that internally has a DynamicControl. (Thus has all of the features of a DynamicControl.)

动态数据引入了一个称为DynamicControl的新Web控件。 可以在FormView和ListView控件中使用它来提供基于数据库级架构的UI。 使用GridView和DetailsView时,添加一个DynamicField,它是内部具有DynamicControl的BoundField的替代。 (因此具有DynamicControl的所有功能。)

This results in your Grids and data entry forms being built around tables and columns of your database with whatever smart data entry controls you like, such as the AJAX Control Toolkit's MaskedTextBoxExtender on a textbox or your favorite third party controls. The database schema also determines the validators for this column. That avoids errors implementing the right validators or updating them when the database schema is modified. (No more "how do I validate a BoundField?" issues!)

这样就可以使用您喜欢的任何智能数据输入控件(例如,文本框上的AJAX控件工具包的MaskedTextBoxExtender或您喜欢的第三方控件)围绕数据库的表和列构建表格和数据输入表单。 数据库模式还确定该列的验证器。 这样可以避免在修改数据库模式时实现正确的验证器或更新它们的错误。 (不再出现“如何验证BoundField?”问题!)

To me, Dynamic Data is a major step forward in developing data entry oriented web applications for ASP.NET.

对我来说,动态数据是为ASP.NET开发面向数据输入的Web应用程序的重要一步。

One of the demo's that is often shown is Dynamic Data's "scaffolding" feature. Basically, you point the wizard at a database and "poof" you've got a nice DataGrid Admin-like site. However, to dismiss it as a scaffolding tool is just the mistake I made when I first saw it.

经常显示的演示之一是Dynamic Data的“脚手架”功能。 基本上,您将向导指向数据库,然后“欺骗”您有一个不错的DataGrid Admin-like网站。 但是,将其作为脚手架工具摆弄只是我第一次看到它时所犯的错误。

它是如何工作的? (How does it work?)

There's a LOT of cool plumbing to Dynamic Data and I'll try to work with the team to get a podcast or two done and some articles explaining the deep how. Here's the basic how.

动态数据方面有很多不错的选择,我将尝试与团队合作完成一两个播客,还有一些文章介绍了深入的方法。 这是基本的方法。

You can make a new Dynamic Data Website and it looks pretty much the same as any other site, because it is. It's a WebForms site just like any others, except for a new folder, called DynamicData. That folder has a web.config of its own to block access. This is the convention. Let's open it up.

您可以创建一个新的动态数据网站,它看起来与其他任何网站都差不多。 它是一个WebForms站点,与其他站点一样,只是一个名为DynamicData的新文件夹。 该文件夹具有自己的web.config来阻止访问。 这是惯例。 让我们打开它。

image

Let's say I want some serious customization. Let's so that the page for the Products table should be TOTALLY custom, but just the ListDetails page. I'll put that under /CustomPages. Let's say I want to use a Telerik control for DateTimes, Integers, and TextAreas, but just some of them.

假设我想要一些认真的定制。 让我们让“产品”表的页面应该是完全自定义的,而仅仅是ListDetails页面。 我将其放在/ CustomPages下。 假设我想对DateTimes,Integers和TextAreas使用Telerik控件,但其中仅一部分。

image

Nothing HAS to look the way it comes by default. Everything is customizable. If I want grid paging to look like whatever i want, I change the GridViewPager.ascx. You can customize at the Table, Column and DataType level.

默认情况下,没有任何东西看起来像它。 一切都是可定制的。 如果我希望网格分页看起来像我想要的任何东西,那么我可以更改GridViewPager.ascx。 您可以在表,列和数据类型级别进行自定义。

I can put "hints" on a metadata-specific class like this:

我可以将“提示”放在特定于元数据的类上,如下所示:

[Range(0, 100)]
[UIHint("IntegerTelerik")]
public object UnitsOnOrder { get; set; }

That UIHint will be used later when I hook up a DynamicControl. As soon as DynamicData sees I'm bound to the UnitsOnOrder column, it'll automatically find IntegerTelerick_Edit - based on the naming and location convention - when it needs to show the "Edit" state. I can set it on a pull column basis, and then I can change it everywhere from one place.

当我连接DynamicControl时,将使用该UIHint。 一旦DynamicData看到我绑定到UnitsOnOrder列,它会在需要显示“ Edit”状态时自动根据名称和位置约定查找IntegerTelerick_Edit。 我可以在拉列的基础上进行设置,然后可以从一个地方到处进行更改。

Here's what that ASCX looks like in code:

这就是ASCX在代码中的样子:

<%@ Control Language="C#" Inherits="System.Web.DynamicData.FieldTemplateUserControl" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Linq" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<script runat="server">

protected void Page_Load(object sender, EventArgs e) {
var metadata = MetadataAttributes.OfType<System.ComponentModel.DataAnnotations.RangeAttribute>().FirstOrDefault();
if (metadata != null) {
RadSlider1.MinimumValue = (int)metadata.Minimum;
RadSlider1.MaximumValue = (int)metadata.Maximum;
}

}

protected override void ExtractValues(IOrderedDictionary dictionary) {
dictionary[Column.Name] = ConvertEditedValue(RadSlider1.Value.ToString());
}

</script>

<telerik:RadSlider ID="RadSlider1" runat="server" Value="<%# (short)FieldValue %>" />

See how it's generic (by that I mean non-specific, not CLR Generic)?  I've replaced the Textbox that is usually used for an Integer and am using a Telerik Slider. The [Range] attribute can be pulled off and popped into this instance of the control.

看看它的通用性(我的意思是非特定的,不是CLR通用的)吗? 我已经替换了通常用于整数的文本框,并且正在使用Telerik滑块。 可以拉出[Range]属性,并弹出该控件实例。

Here it is at runtime, next to some other Integer columns:

这是在运行时,在其他一些Integer列旁边:

image

Now, I get to think about selecting the correct DataType via UIHint rather than using the ASCX directly. It makes the control really reusable within the context of data binding and keeps me from repeating myself.

现在,我开始考虑通过UIHint选择正确的数据类型,而不是直接使用ASCX。 它使控件在数据绑定的上下文中真正可重用,并且避免我重复自己。

I can add Validation Controls to a data type, so the Validation exists in one place, rather than repeated all over. For example, if you wanted to swap out validation for one, or all, your controls, to use Peter's Validation and More (which rocks, by the way, we bought a site license at my last job) than you'd do it once per data type.

我可以将验证控件添加到一种数据类型,因此验证存在于一个位置,而不是一遍又一遍。 例如,如果您想换一个或所有控件的验证,以使用Peter的Validation and More (顺便说一句,我们在上一份工作中购买了站点许可证)比您一次完成每个数据类型。

This is just one VERY simple example, but it's, I think, I pretty good one. Thanks to Scott Hunter for helping me out with this as well as my talk at Devscovery last week. There are some good Dynamic Data samples he's done that you can download and check out. One includes a "before and after" application that shows how an address book would be coded using the new DynamicControl and the older way (using BoundControl).

这只是一个非常简单的示例,但我认为这是一个非常不错的示例。 感谢Scott Hunter以及上周在Devscovery上的演讲为我提供了帮助。 他已经完成一些不错的Dynamic Data示例,您可以下载并签出。 其中包括一个“ before and after”应用程序,该应用程序显示了如何使用新的DynamicControl和较旧的方法(使用BoundControl)对地址簿进行编码。

An even cooler (and advanced) example is one where Scott Hunter wants to pull an funky binary encoded image out of an old database. He makes a custom control that handles a custom data type called "DbImage" and completely encapsulates the display of that column. From the point of view of the GridView, it's just a DynamicControl that shows itself as an <img> tag. 

一个更酷(更高级)的示例是Scott Hunter想要从旧数据库中提取一个时髦的二进制编码图像的示例。 他制作了一个自定义控件,该控件处理称为“ DbImage”的自定义数据类型,并完全封装了该列的显示。 从GridView的角度来看,它只是一个动态控件,将其显示为<img>标签。

嘘,ASP.NET变化太快,这太多了 (Sheesh, ASP.NET is changing too fast, this is too much to absorb)

This is a big deal to me because it's going to make a subset of my work easier. If I've got a database and I don't mind using LINQ to SQL or LINQ to Entities (for now), I'll be able to create CRUD (Create, Read, Update, Delete) websites WAY faster.

对我来说,这重要,因为这会使我的工作变得更轻松。 如果我有数据库,并且不介意使用LINQ to SQL或LINQ to Entities(目前),那么我将能够更快地创建CRUD(创建,读取,更新,删除)网站。

Projects with Dynamic Data will be more customizable than those "typical Microsoft demos" where someone drags a DataSource and GridView over to the Design Surface, shows you a list of Products from Northwind then waits for applause. ;)

具有动态数据的项目将比那些“典型的Microsoft演示”更具可自定义性,在“典型的Microsoft演示”中,有人将DataSource和GridView拖到设计图面,向您显示Northwind的产品列表,然后等待掌声。 ;)

Why is this NOT a big deal? Everything you are used to still works as before. This is additive and simple if you just want to avoid repeating yourself.

为什么这不是什么大不了的? 您所习惯的一切仍然可以像以前一样工作。 如果您只是想避免重复自己,那么这是累加和简单的。

为什么在代码库中显示? (Why is it on Code Gallery?)

You might notice that this pre-release drop is on MSDN Code Gallery, that's a temporary thing to get your feedback. It'll eventually find a home on http://www.asp.net as it's ultimately part of the larger ASP.NET framework.

您可能会注意到,此预发布版本位于MSDN Code Gallery上,这是获得您的反馈的暂时措施。 最终它将成为http://www.asp.net上的主页,因为它最终是更大的ASP.NET框架的一部分。

Here's a diagram that we've used internally to decide where to put stuff. Consider this drop to be a "showcase" ;) as it'll only be up for a little while. If you have issues, bugs, opinions on Dynamic Data, go put them in the Issue Tracker as the team is watching closely!

这是我们在内部用来确定放置位置的图表。 将此下降视为“展示柜”;),因为它只会停留一会儿。 如果您对动态数据存在问题,错误和意见,请在团队密切关注的情况下将它们放入问题跟踪器中!

clip_image001

Note: This Dynamic Data project at Code Gallery is a very temporary home for ASP.NET Dynamic Data in order to gather feedback. When ASP.NET Dynamic Data appears in an 'official' release, we will remove the release from this site and redirect you to the new 'official' release.

注意: Code Gallery上的此Dynamic Data项目是ASP.NET Dynamic Data的一个非常临时的主页,目的是收集反馈。 当ASP.NET动态数据出现在“官方”发行版中时,我们将从该站点中删除该发行版,并将您重定向到新的“官方”发行版。

您应该害怕此版本吗? (Should you Fear This Release? )

It's a pre-release build, but it's pretty harmless. It does install a few Project Templates in VS, but it shouldn't screw up your VS install. If you are using ASP.NET MVC, be aware that this drop includes a version of the ASP.NET Routing. This will be reconciled when they all are released, but for now, be aware of your version numbers.

这是一个预发行版本,但没有任何危害。 它确实在VS中安装了一些项目模板,但是它不应该增加VS的安装量。 如果您使用的是ASP.NET MVC,请注意,此删除包含ASP.NET Routing的版本。 当它们全部发布时,将对此进行协调,但是现在,请注意您的版本号。

"This release includes the Dynamic Data runtime assemblies as well as versions of the System.Web.dll and System.Web.Extensions.dll assemblies that have been updated from the versions in the .NET Framework 3.5. The release also installs Visual Basic and C# templates that you can use in Visual Studio 2008 for creating a Dynamic Data Web site."

“此版本包括动态数据运行时程序集以及从.NET Framework 3.5中的版本更新的System.Web.dll和System.Web.Extensions.dll程序集的版本。该版本还安装了Visual Basic和您可以在Visual Studio 2008中使用的C#模板来创建动态数据网站。”

These updated DLLs will be GAC'ed, and there's a batch file for installing and uninstalling. The changes are largely additive, but if you're deeply risk-adverse, use a VM. The batch file will make it clear what's changing on your system and what's not. Be aware there's a different batch file for 64-bit vs. 32-bit systems. This will all be automatic in the final release as it'll be rolled into the .NET Framework.

这些更新的DLL将被GAC修改,并且有一个用于安装和卸载的批处理文件。 所做的更改在很大程度上是累加的,但是如果您极不愿意冒险,请使用VM。 批处理文件将使您清楚系统上发生了什么变化以及未发生什么变化。 请注意,对于64位和32位系统,存在一个不同的批处理文件。 在最终版本中,这将是自动的,因为它将被卷入.NET Framework。

简而言之,动态数据 (Dynamic Data in a Nutshell)

If you're using Data Binding and any of the DetailsView, FormView, GridView, or ListView controls to do CRUD, consider using Dynamic Data, especially if you're using the BoundColumn. It will save you time and trouble.

如果您使用数据绑定和DetailsViewFormViewGridViewListView控件中的任何一个来执行CRUD,请考虑使用动态数据,尤其是在使用BoundColumn的情况下。 这样可以节省您的时间和麻烦。

In the future, watch for the possibility of Dynamic Data for POCO (my term, not the teams), Dynamic Data for Silverlight and Dynamic Data for MVC. Now is your opportunity to be heard. I'd like the idea of Dynamic Data for NHibernate myself, so I'm pushing for that. Feel free to engage in the Dynamic Data Forums or post bugs on this release in the issue tracker.

将来,请注意POCO的动态数据(用我的话说,不是团队),Silverlight的动态数据和MVC的动态数据的可能性。 现在是您倾听的机会。 我本人想为NHibernate设计动态数据,所以我为此努力。 随时参与动态数据论坛,在问题跟踪器中发布此版本的错误。

Related Links

相关链接

翻译自: https://www.hanselman.com/blog/putting-aspnet-dynamic-data-into-context

asp.net数据动态曲线

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值