asp.net ado_ASP动态数据预览-利用ADO.NET数据服务获得更多乐趣和收益的更多方法...

asp.net ado

asp.net ado

There's lots of interesting stuff going on in the ASP.NET team, and you can usually learn/glean/figure out most of it (if you're interested) by poking around the Codeplex ASP.NET site. They update it all the time, and you can watch their thinking. They put all sorts of stuff up there, ideas they are floating, directions they are considering and (really early) previews of those ideas and directions in the form of code. It's not production ready, more brainstorming - that's why it's on CodePlex, and why they don't exactly advertise the heck out of it.

ASP.NET团队中发生了很多有趣的事情,通常您可以在Codeplex ASP.NET网站上四处学习/整理/弄清楚其中的大部分内容(如果您有兴趣的话)。 他们一直在更新它,您可以观察他们的想法。 他们把各种各样的东西放在那里,他们在浮动想法,他们正在考虑的方向,并且(真的很早)以代码的形式预览了这些想法和方向。 它还没有准备好投入生产,需要更多的头脑风暴-这就是为什么要在CodePlex上使用它,以及为什么他们没有完全宣传它的原因。

There's a release of ASP.NET Dynamic Data 4.0 Preview 2 that was quietly put up just a month ago with this scary disclaimer:

有一个发布版本的ASP.NET动态数据4.0预览版2在一个月前悄悄发布,带有可怕的免责声明:

NOTE: These previews contains features that may not be in the next version of the framework. These previews are not production quality and should be used at your own risk.

注意:这些预览版包含了下一版框架中可能没有的功能。 这些预览不是高质量的产品,应自担风险。

动态数据4.0预览版2 (Dynamic Data 4.0 Preview 2)

image

Let's poke around the SampleProject Solution that's included with this preview download. There's five projects showing off a number of new feature possibilities.

让我们来看看此预览下载中包含的SampleProject解决方案。 有五个项目展示了许多新功能。

  • BusinessLogicDataSource – A showcase for a new BusinessLogicDataSource that combines customizability of ObjectDataSource with the flexibility of LINQ and the IQueryable interface. Also, a new QueryExtender feature allowing high-level query composition in markup is demonstrated.

    BusinessLogicDataSource –一个新的BusinessLogicDataSource的展示,它将ObjectDataSource的可自定义性与LINQ和IQueryable接口的灵活性相结合。 此外,还演示了一种新的QueryExtender功能,该功能允许在标记中进行高级查询组合。

    I don't really like the name for this (at all) but it's brainstorming at this point.

    我真的不太喜欢这个名字,但在这一点上它正在集思广益。

  • DataServicesServer and DataServicesClient - illustrates the use of ADO.NET Data Services with Dynamic Data. This is the stuff I think is really interesting and what I'll focus on in this post.

    DataServicesServer和DataServicesClient-说明了将ADO.NET数据服务与动态数据一起使用。 这是我认为真的很有趣的东西,也是我在本文中将重点介绍的内容。

  • DynamicDataFuturesSample - contains the existing Dynamic Data Futures sample that has been available. This sample does not add any new functionality in comparison to the old Futures project except for running on new Dynamic Data assemblies.

    DynamicDataFuturesSample-包含现有的可用的Dynamic Data Futures示例。 与在旧的Futures项目相比,此示例没有添加任何新功能,只是在新的Dynamic Data程序集上运行。

  • SampleProject – Shows the next generation of Dynamic Data features including support for Entity Framework and Linq to SQL inheritance, many to many support for Entity Framework, Entity templates and the new templated filters that are based on the QueryExtender.

    SampleProject –显示下一代动态数据功能,包括对Entity Framework和Linq to SQL继承的支持,对Entity Framework,Entity模板和基于QueryExtender的新模板化筛选器的多对多支持。

The two I'm interested in are the DataServicesServer and Client.

我感兴趣的两个是DataServicesServer和Client。

快速复审 (Quick Review)

Before I talk about them, let's review some of the things we can, as developers, choose from in .NET 3.5 on the Data side. You've got lots of choices:

在讨论它们之前,让我们回顾一下作为开发人员可以从.NET 3.5的“数据”端中进行选择的一些事情。 您有很多选择:

  • Linq to SQL (Server): If you don't mind your objects being nearly 1:1 with data model, it's fast and easy to use. Stackoverflow.com uses it. Some folks are freaking out thinking it's "dead." But I think that's silly. More on that later. I use it all the time. Know what it can do, know what it's not good for.

    Linq to SQL(服务器):如果您不介意对象与数据模型的比例接近1:1,那么它的使用将非常快速且容易。 Stackoverflow.com使用它。 有些人吓坏了,认为这是“死角”。 但是我认为这很愚蠢。 以后再说。 我用它所有的时间。 知道它能做什么,知道它没有什么好处。

  • Entity Framework: If you want more control over what your Data Access Layer (DAL) objects look like, and there's not a 1:1 relationship between your objects and the database. If you are using not just SQL Server, but other databases like Oracle, etc.

    实体框架:如果您想更好地控制数据访问层(DAL)对象的外观,并且对象与数据库之间没有1:1的关系。 如果您不仅使用SQL Server,还使用其他数据库,例如Oracle等。

  • Your own thing: Lots of folks write their own DALs with DataReaders loading objects, etc. I used to do this with CodeSmith generating all the boring stuff.

    你自己的事情:很多人都用DataReaders加载对象等来编写自己的DAL。我过去常常使用CodeSmith来生成所有无聊的东西。

  • NHibernate (OSS): Define your Domain, define a mapping (from a number of possible ways) and configure.

    NHibernate(OSS):定义您的域,定义映射(从多种可能的方式)并进行配置。

  • Subsonic: Can be used two ways, as an regular ORM (Object Relational Mapper) or as a no-code DAL provider.

    亚音速:可以使用两种方式,作为常规ORM(对象关系映射器)或无代码DAL提供程序。

On the Web side, you can make your "angle-brackets" and HTML UIs ;) a number of ways:

Web端,您可以通过多种方式使“尖括号”和HTML UI;):

  • ASP.NET Web Forms - Programming the web with a controls and event model.

    ASP.NET Web窗体-使用控件和事件模型对Web进行编程。

    • Classic Demo: Drag a grid, drag a data source, setup some binding markup. Boom, page.

      经典演示:拖动网格,拖动数据源,设置一些绑定标记。 繁荣,页面。

  • ASP.NET MVC - Testable, extensible. Control over your markup and your programming model.

    ASP.NET MVC -可测试,可扩展。 控制您的标记和编程模型。

    • Classic Demo: Write a test, fail, fix, pass. Create a model, create a view, hook up the controller. Boom, page.

      经典演示:编写测试,失败,修复,通过。 创建模型,创建视图,连接控制器。 繁荣,页面。

  • ASP.NET Dynamic Data - Dynamically generating sites using templates over a meta-model.

    ASP.NET动态数据 -使用元模型上的模板动态生成网站。

    • Classic Demo: File | New ASP.NET Dynamic Data site. Let it know about your Data Context. Edit the templates to test. Boom, site.

      经典演示:文件| 新的ASP.NET动态数据站点。 让它知道您的数据上下文。 编辑模板进行测试。 繁荣,现场。

If you aren't generating UI angle-brackets, but rather data-specific angle-brackets, like XML, or even JSON, you can use:

如果您不是生成UI尖括号,而是生成特定于数据的尖括号,例如XML甚至JSON,则可以使用:

  • ADO.NET Data Services (codename: Astoria): You can take any IQueryable objects and get a nice AtomPub/REST Web Service interface based on WCF (Windows Communication Foundation). This isn't a database-specific technology; you can make data services just with List<MyObject>. Anything with a LINQ provider can be a service. Astoria is a great way to take a client application that may have needed direct database access and turn it into an app that talks HTTP over Port 80. It's also a great way to get JSON back for your jQuery ajax() calls or by using ADO.NET Data Services direct Javascript support.

    ADO.NET数据服务(代码名称:Astoria):您可以获取任何IQueryable对象,并基于WCF(Windows Communication Foundation)获得一个不错的AtomPub / REST Web服务接口。 这不是特定于数据库的技术。 您可以仅使用List <MyObject>进行数据服务。 带有LINQ提供程序的任何东西都可以成为服务。 Astoria是将可能需要直接数据库访问的客户端应用程序转换为可通过端口80进行HTTP通讯的应用程序的绝佳方法。这也是为jQuery ajax()调用或使用ADO取回JSON的一种很好的方法。 .NET数据服务直接支持Javascript

连连看 (Mix and Match)

For the most part, you can happily mix and match these different technologies as much as you like. That means you can use ASP.NET MVC with NHibernate, or Web Forms with Subsonic.

在大多数情况下,您可以随意混合并匹配这些不同的技术。 这意味着您可以将ASP.NET MVC与NHibernate一起使用,或将Web Forms与Subsonic一起使用。

Some have some requirements, usually an interface to implement or a provider to provide. For example, if you have an IQueryable (LINQ) implementation, you can use ADO.NET Data Services. If you've got LINQ for Subsonic, you get ADO.NET Data Services for free. If you want Updates, you implement IUpdateable. (Here's a LINQ to SQL IUpdateable implementation, and why you should care.)

有些有一些要求,通常是要实现的接口或要提供的提供者。 例如,如果您具有IQueryable(LINQ)实现,则可以使用ADO.NET数据服务。 如果您拥有LINQ for Subsonic,则可以免费获得ADO.NET数据服务。 如果需要更新,请实现IUpdateable。 (这是LINQ to SQL IUpdateable的实现,以及您为什么要关心它。)

However, ASP.NET Dynamic Data does a LOT of stuff for you. It needs a complete "meta-model" populated that describes the data and needs to understand how to update that data. It's pretty specific to the underlying database (or ORM, or whatever) technology, so you need a provider that is specific. That DataModelProvider (and a few others) get the metadata from your source and pass it to ASP.NET Dynamic Data. ASP.NET 3.5 SP1 ships with providers for Entity Framework and Linq to SQL.

但是,ASP.NET动态数据可以为您做很多事情。 它需要一个完整的“元模型”来描述数据,并且需要了解如何更新该数据。 它非常特定于基础数据库(或ORM或其他)技术,因此您需要特定的提供程序。 该DataModelProvider(以及其他一些)从您的源中获取元数据,并将其传递给ASP.NET动态数据。 ASP.NET 3.5 SP1附带了用于实体框架和SQL的Linq的提供程序。

You could implement your own, if you have an existing database/access technology. Someone could write some NHibernate or Subsonic providers, then get all the Dynamic Data stuff to sit on top.

如果您具有现有的数据库/访问技术,则可以实施自己的数据库。 有人可以编写一些NHibernate或Subsonic提供程序,然后将所有Dynamic Data内容放在首位。

I really like keeping my websites from having direct access to the database, at least when I'm doing big Enterprise work. One of the rules the security guys always drilled into us was to assume that the web server has already been compromised. Basically, assume they (the baddies) OWN (or PWN) it, and code appropriately. There's a number of ways to do this, but one way to limit access to your database is to create a very limited Web Services/REST interface to be called from the Web Server.

我真的很喜欢阻止我的网站直接访问数据库,至少在我从事大型企业工作时。 安全人员经常钻研给我们的规则之一是假设Web服务器已经受到威胁。 基本上,假设它们(坏人)为OWN(或PWN),并进行适当的编码。 有很多方法可以执行此操作,但是限制访问数据库的一种方法是创建一个非常有限的Web服务/ REST接口,以从Web服务器调用该接口。

Back to ASP.NET Dynamic Data. There's no provider that lets you point ASP.NET Dynamic Data to a ADO.NET Data Service...except there is in this preview.

返回ASP.NET动态数据。 没有任何提供程序可让您将ASP.NET动态数据指向ADO.NET数据服务...除非此预览中存在。

预览项目-DataServicesClient和DataServicesServer (The Preview Projects - DataServicesClient and DataServicesServer)

If you check out the web.config of the DataServicesClient project, you can see he's added client-side assembly redirects to force the loading of his private builds of two assemblies:

如果您检出DataServicesClient项目的web.config,则可以看到他添加了客户端程序集重定向,以强制加载两个程序集的私有构建:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.DataAnnotations" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="3.5.0.0" newVersion="99.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.DynamicData" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="3.5.0.0" newVersion="99.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>

There's two changed files with the goofy build number of 99.0.0.0. Those are preview DLLs. After this, it  looks pretty much like a standard Dynamic Data ASP.NET site.  There's a client-side DataContext generated from a standard, unchanged, ADO.NET Data Service and it gets registered in the Global.asax:

有两个更改的文件,其高飞内部版本号为99.0.0.0。 这些是预览DLL。 此后,它看起来很像一个标准的Dynamic Data ASP.NET网站。 从标准的,不变的ADO.NET数据服务生成了一个客户端DataContext,并在Global.asax中进行了注册:

MetaModel model = new MetaModel()
model.RegisterContext(
new DataServiceDataModelProvider(
typeof(NORTHWNDModel.NorthwindClientEntities)),
new ContextConfiguration() { ScaffoldAllTables = true });

The Dynamic Data system gets all its meta-model information from the DataServiceDataModelProvider pass in there. It's currently in Microsoft.Web.Misc.dll along with some other very telling (at least at the time, but surprising no one noticed) stuff like "RedDogDataServiceContext" and "SDSDataServiceContext." (The last one is a silly name, expanding to SQL Data Service Data Service Context. ;) )

动态数据系统从那里传递的DataServiceDataModelProvider获取所有其元模型信息。 它目前与其他一些很有说服力的东西(至少在当时,但没有人注意到的)一起在Microsoft.Web.Misc.dll中,例如“ RedDogDataServiceContext”和“ SDSDataServiceContext”。 (最后一个是一个愚蠢的名字,扩展到SQL Data Service数据服务上下文。))

但不仅仅是动态数据,WebForms (But not just Dynamic Data, WebForms, too)

In the DynamicData Templates, there's a reference to a new DataSource control called DataServiceLinqDataSource. That's included in this preview. This is cool because it not only hooks up nicely to the templates, but it can be used outside Dynamic Data. You can use it in Web Forms just like this using a ListView or GridView or whatever.

在DynamicData模板中,有对名为DataServiceLinqDataSource的新DataSource控件的引用。 该预览中已包含该内容。 这很酷,因为它不仅可以很好地连接到模板,而且可以在Dynamic Data外部使用。 您可以像这样使用ListView或GridView或其他任何形式在Web窗体中使用它。

<asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource"
AutoGenerateEditButton="true" AutoGenerateDeleteButton="true"
AllowPaging="True" AllowSorting="True">
</asp:GridView>

<asp:DataServiceLinqDataSource ID="GridDataSource"
ContextTypeName="NORTHWNDModel.NorthwindClientEntities" TableName="Products"
runat="server" EnableDelete="true" EnableUpdate="true">
</asp:DataServiceLinqDataSource>

This way you can use ADO.NET Data Services wherever. In markup, in code-behind, in Dynamic Data sites, or some combination of them all - staying off the database directly and talking REST (AtomPub) Web Services instead from you Web Services, so you go from this:

这样,您可以在任何地方使用ADO.NET数据服务。 在标记,代码隐藏,动态数据站点或它们的某种组合中-直接不使用数据库,而是使用REST(AtomPub)Web服务而不是Web服务,因此,您可以从此开始:

image

To this:

对此:

image

Again, bask in the wonderful Paint-y ness of my lovingly created high-quality diagrams.

同样,沉浸于我精心创建的高质量图表的奇妙绘画风格。

I personally think that this is an important addition and fills a hole. If you agree and think it should be a part of something in the future, tell Scott Hunter (crush him with email!) the Program Manager for ASP.NET Dynamic Data. He put this release up for feedback, so contact him if you've got ideas, comments or feel strongly about something. Or leave a comment here and I'll tell him.

我个人认为这是一个重要的补充并且填补了空白。 如果您同意并认为将来应该成为其中的一部分,请告诉Scott Hunter (通过电子邮件粉碎他! )ASP.NET动态数据的程序管理器。 他发布了此版本以征询反馈,因此如果您有想法,意见或对某件事有强烈的感觉,请与他联系。 或者在这里发表评论,我会告诉他。

翻译自: https://www.hanselman.com/blog/asp-dynamic-data-preview-more-ways-to-exploit-adonet-data-services-for-fun-and-profit

asp.net ado

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值