开发者

Which design pattern should I use to write an ASP.net page that persists to a DB?

Is there a design pattern I can use in asp.net pages that will help me program pages more effieciently? In particular its when I have to save something to a databa开发者_开发知识库se and then set up some page controls etc...


ASP.NET Page shouldn't be used to realise DB centric tasks. You should introduce Data Access Layer and then

You should consider:

Repository Pattern

A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection. Client objects construct query specifications declaratively and submit them to Repository for satisfaction. Objects can be added to and removed from the Repository, as they can from a simple collection of objects, and the mapping code encapsulated by the Repository will carry out the appropriate operations behind the scenes. Conceptually, a Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer. Repository also supports the objective of achieving a clean separation and one-way dependency between the domain and data mapping layers.

ActiveRecord Pattern

Active record is an approach to accessing data in a database. A database table or view is wrapped into a class. Thus, an object instance is tied to a single row in the table. After creation of an object, a new row is added to the table upon save. Any object loaded gets its information from the database. When an object is updated the corresponding row in the table is also updated. The wrapper class implements accessor methods or properties for each column in the table or view.


Microsoft would tell you to go with ASP.NET MVC3 and Entity Framework 4+.

However, this is kind of a generic question, and the real answer for you depends on a lot of different stuff, including what your app needs to do, how complex it is, blah blah blah.

With mentions of "web pages" and "saving to databases", first thing that comes to mind is an ORM (that's the Entity Framework) working with an MVC frameworked web application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜