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

推荐订阅源

N
News and Events Feed by Topic
WordPress大学
WordPress大学
Vercel News
Vercel News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
小众软件
小众软件
L
LangChain Blog
雷峰网
雷峰网
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
NISL@THU
NISL@THU
Scott Helme
Scott Helme
量子位
S
Security Affairs
T
Threat Research - Cisco Blogs
博客园_首页
云风的 BLOG
云风的 BLOG
D
Docker
AWS News Blog
AWS News Blog
腾讯CDC
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
U
Unit 42
Recent Announcements
Recent Announcements
Apple Machine Learning Research
Apple Machine Learning Research
G
Google Developers Blog
T
The Exploit Database - CXSecurity.com
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 热门话题
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The Last Watchdog
The Last Watchdog
C
Cybersecurity and Infrastructure Security Agency CISA
IT之家
IT之家
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
F
Full Disclosure
L
Lohrmann on Cybersecurity
The Hacker News
The Hacker News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Y
Y Combinator Blog
S
Security @ Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
C
Check Point Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
N
News and Events Feed by Topic
PCI Perspectives
PCI Perspectives
I
InfoQ

博客园 - Animax!

The Tao of Programming Light weight Framework (AnyBase) -- 通信模块说明 关于WinIO.DLL的键盘输入模拟 Light weight Framework (AnyBase) -- Core 模块说明 开源项目 Light weight Framework (AnyBase) 发布 DB4o的缓存机制 Winfrom界面异步操作的一个解决方法 db4o 研究--性能测试 MVC — 笔记 WF笔记 – Workflow概念 WCF Demo – Http、TCP Host - Animax! LINQ TO SQL 笔记 — 存储过程、并发与事务 WCF笔记 - 绑定 WCF 笔记 正则表达式[转载整理] - Animax! - 博客园 LINQ 笔记 - LINQ to SQL 基本数据操作 - Animax! LINQ 笔记 - 语法与关键字 LINQ 笔记- Lambda Excel导入SQL - Animax! - 博客园
Asp.net动态数据(Dynamic Data) 笔记一
Animax! · 2008-10-20 · via 博客园 - Animax!

2008-10-20 13:17  Animax!  阅读(4523)  评论()    收藏  举报

Dynamic Data:

    Asp.net Dynamic Data 是一个快速开发框架,只需要指定Linq To Sql 或 ADO.Net Entity 数据实体并设置动态数据模板它便能动态生成整个网站。

创建Dynamic Data Web Site:

    使用安装了sp1补丁的Visual Studio 2008 新建网站。在网站模板中有两个Dynamic Data网站,一个是 "Dynamic Data实体网站(Dynamic Data Entities Web Stie)"它是使用ADO.net Entity作为数据模型的,另一个是 "Dynamic Data 网站(Dynamic Data Web Stie)"。我们新建一个Dynamic Data 网站,用LINQ TO SQL 来作为数据模型。    

    在创建完成后可以发现,Dynamic Data 网站比其他网站多了一个文件夹DynamicData,这文件夹里面放置的是生成网站的模板。    

创建数据模型:

    直接在网站中新建一个LINQ To sql类。

    打开Global.asax,取消注释数据模型注册那句代码:

    model.RegisterContext(

          typeof(YourDataContextType), new ContextConfiguration() { ScaffoldAllTables = true });

    并将其中的YourDataContextType替换成LINQ TO SQL生成的DataContext。

Dynamic Data 网站:

    直接运行项目,Asp.net Dynamic Data 便按照数据模型动态生成了整个网站。

Routing:

    再次打开Global.asax观看里面的代码,发现Dynamic Data也使用了Routing:

        routes.Add(new DynamicDataRoute("{table}/{action}.aspx"{

            Constraints 
= new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),

            Model 
= model

        }
);

    把一个继承自Route的DynamicDataRoute添加到Routing规则表中。添加的这个规则只规定了只是接受Action为List、Details、Edit、Insert的访问。

    可以看出,这四个Aciton是对应着DynamicData/PageTemplates文件夹中的四个页面文件。在那文件夹中还有一个ListDetails.aspx页面文件,是用于"合并页模式",就是所有的操作都会在一页中完成。

    要打开这个功能需要在Global.asax里注释掉上面的代码,并且反注释下面的代码断:

        routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
        
{
            Action 
= PageAction.List,
            ViewName 
= "ListDetails",
            Model 
= model
        }
);


        routes.Add(
new DynamicDataRoute("{table}/ListDetails.aspx")
        
{
            Action 
= PageAction.Details,
            ViewName 
= "ListDetails",
            Model 
= model
        }
);

     这里的作用是让Action为PageAction.List和PageAction.Details都访问到名为ListDetails的视图上,根据MVC的约定,就是使用ListDetails.aspx为视图页面。