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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Troy Hunt's Blog
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
T
Tenable Blog
L
LINUX DO - 热门话题
V
Visual Studio Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
Cisco Talos Blog
Cisco Talos Blog
A
Arctic Wolf
C
Cyber Attacks, Cyber Crime and Cyber Security
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
Know Your Adversary
Know Your Adversary
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
N
Netflix TechBlog - Medium
SecWiki News
SecWiki News
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
Project Zero
Project Zero
W
WeLiveSecurity
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans
Recorded Future
Recorded Future
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
S
Securelist
Spread Privacy
Spread Privacy
L
LangChain Blog
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The Last Watchdog
The Last Watchdog
Attack and Defense Labs
Attack and Defense Labs
博客园 - 司徒正美
Help Net Security
Help Net Security
L
Lohrmann on Cybersecurity
人人都是产品经理
人人都是产品经理
Forbes - Security
Forbes - Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
PCI Perspectives
PCI Perspectives
博客园 - 【当耐特】
T
Tor Project blog

博客园 - 朱峰(Peter.zhu)

[转]Becoming a JavaScript ninja 【转载】关于大型asp.net应用系统的架构—如何做到高性能高可伸缩性 【javascript】Lazy Load, 延迟加载图片的 jQuery 插件 【译】15个必须知道的chrome开发者技巧 Implementing multi-level trees in MS SQL Server 【转】Linq to EF 与Linq to Object 使用心得 Implementing the Singleton Pattern in C# 【转】【翻译】The Top 10 Mistakes That KnockoutJS Developers Make 【转载】net的nuget无法更新解决 c# ASP.Net 使用开源免费类库操作Excel VISUAL STUDIO 使用技巧大全 中英文版本之 一 - 命名空间引用管理 Redirect and Post JSON object in ASP.NET MVC 【引】Difference between Asp.Net WebForm and Asp.Net MVC 【引】How to Choose the Best Way to Pass Multiple Models in ASP.NET MVC 【引】Version Control System - SVN - Deployments Best Practices 【引】Version Control System - SVN - Developing and Deploying with Branches Javascript基础复习 - jQuery Proxy函数 【转】Domain Driven Design - Clear Your Concepts Before You Start 【转】单体模式-经典实现 Implementing the Singleton Pattern in C#
ASP.NET之ORM模型 - ActiveRecord 模式
朱峰(Peter.zhu) · 2013-12-25 · via 博客园 - 朱峰(Peter.zhu)

2013-12-25 18:00  朱峰(Peter.zhu)  阅读(588)  评论()    收藏  举报

ActiveRecord也属于ORM层,由Rails最早提出,遵循标准的ORM模型:表映射到记录,记录映射到对象,字段映射到对象属性。

配合遵循的命名和配置惯例,能够很大程度的快速实现模型的操作,而且简洁易懂。

ActiveRecord的主要思想是:

1. 每一个数据库表对应创建一个类,类的每一个对象实例对应于数据库中表的一行记录;通常表的每个字段在类中都有相应的Field;
2. ActiveRecord同时负责把自己持久化,在ActiveRecord中封装了对数据库的访问,即CURD;;
3. ActiveRecord是一种领域模型(Domain Model),封装了部分业务逻辑;

ActiveRecord比较适用于:

1. 业务逻辑比较简单,当你的类基本上和数据库中的表一一对应时, ActiveRecord是非常方便的,即你的业务逻辑大多数是对单表操作;
2. 当发生跨表的操作时, 往往会配合使用事务脚本(Transaction Script),把跨表事务提升到事务脚本中;
3. ActiveRecord最大优点是简单, 直观。 一个类就包括了数据访问和业务逻辑. 如果配合代码生成器使用就更方便了;
这些优点使ActiveRecord特别适合WEB快速开发。

ActiveRecord不适合于:

1. ActiveRecord虽然有业务逻辑, 但基本上都是基于单表的. 跨表逻辑一般会放到当发生跨表的操作时, 往往会配合使用事务脚本(Transaction Script)中. 如果对象间的关联越来越多, 你的事务脚本越来越庞大, 重复的代码越来越多, 你就要考虑Domain Model + O/R Mapper了;
2. ActiveRecord保存了数据, 使它有时候看上去像数据传输对象(DTO). 但是ActiveRecord有数据库访问能力, 不要把它当DTO用. 尤其在跨越进程边界调用的时候, 不能传递ActiveRecord对象。