TAILIEUCHUNG - ASP.NET 4 Unleased - p 99

Lưu trữ-Chỉ ra một trường hợp giá trị tài sản được lưu trữ. . UpdateCheck-Chỉ có tài sản tham gia vào những so sánh tương tranh lạc quan. Thuộc tính bảng hỗ trợ các tài sản sau đây duy nhất:. Tên-Chỉ ra tên của bảng cơ sở dữ liệu tương ứng với lớp. Một số ý kiến về những thuộc tính này là cần thiết. | 954 CHAPTER 20 Data Access with LINQ to SQL Storage Indicates a field where the value of the property is stored. UpdateCheck Indicates whether the property participates in optimistic concurrency comparisons. The Table attribute supports the following single property Name Indicates the name of the database table that corresponds to the class. Some comments about these attributes are needed. First you don t need to specify a Name property when your property or class name corresponds to your database column or table name. If on the other hand your database table were named Movies and your class were named Movie you would need to supply the Name property for the Table attribute to map the correct table to the class. Second you always want to specify the primary key column by using the IsPrimaryKey property. For example if you don t specify a primary key column you can t do updates against your database using LINQ. Finally even though we didn t do this in our Movie class you almost always want to include a timestamp column in your database table and indicate the timestamp column by using the IsVersion property. If you don t do this LINQ to SQL checks whether the values of all the properties match the values of all the columns before performing an update command to prevent concurrency conflicts. If you specify a version property LINQ to SQL can check the value of this single property against the database rather than all the columns. Now that we ve created an entity we can start performing queries against the database using LINQ to SQL. For example the page in Listing contains a form that enables you to search for movies by a particular director. LISTING Entities @ Page Language C @ Import Namespace @ Import Namespace @ Import Namespace DOCTYPE html PUBLIC - W3C DTD XHTML Transitional EN http TR xhtml1 DTD script runat server protected void .