tailieunhanh - ASP.NET 4 Unleased - p 103
Thực hiện xác thực với các học EntityBase Một đơn khiếu nại Tôi đã luôn luôn có khoảng Framework là xác nhận điều đó xảy ra tại địa điểm sai. Khi xây dựng các trang , bạn viết phần lớn các mã xác thực của bạn trong lớp giao diện người dùng thay vì lớp logic doanh nghiệp của bạn nơi mà mã xác nhận bạn đúng thuộc về. | 994 CHAPTER 20 Data Access with LINQ to SQL from the ObjectDataSource control and provides default values for several ObjectDataSource control properties. For example you could swap the ObjectDataSource control in Listing with the following EntityDataSource control custom EntityDataSource id srcMovies TypeName Movie EnablePaging true SortParameterName orderBy Runat Server Why use the EntityDataSource control Less typing. I don t want to program all day I want to see a movie. Performing Validation with the EntityBase Class One complaint I ve always had about Framework is that validation happens at the wrong place. When building pages you write the vast majority of your validation code in the user interface layer instead of your business logic layer where your validation code properly belongs. Performing validation in your user interface layer is bad for two main reasons. First it means that if you switch user interfaces for your application you must rewrite all your validation logic. For example you might want to create a cool Silverlight interface for your application. In that case you have to write all your validation logic again from scratch. Validation logic should be user interface-independent. Also placing your validation logic in your user interface layer means that you have to rewrite the exact same validation logic on each page that you use an entity. This is an extraordinary time waster. I want to write my validation logic for an entity once and use the same logic everywhere. The EntityBase class includes a Validate method that you can use to incorporate validation logic into your entities and thus your business logic layer . Listing illustrates how you can write the Movie class so that it validates the Title Director and DateReleased properties. LISTING ShowEntityBase App Code using System public partial class Movie EntityBase Movie From the Library of Wow eBook Creating a Custom LINQ Entity Base Class 995 .
đang nạp các trang xem trước