Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
và hiệu quả xây dựng một tài liệu XML trong một tuyên bố duy nhất. Sau đó, bạn thấy làm thế nào để thêm chú thích cho các phần tử và các thuộc tính trong một cây XML bằng cách sử dụng phương pháp AddAnnotation, và làm thế nào để đọc các chú thích một khi họ | Chapter 13 More about Entity Classes To see how this works fire up Visual Studio create a new Windows project and add the appropriate references system.data.Linq Next view the code behind Forml and add the following statements using System.Data.Linq using System.Data.Linq.Mapping Prior to Beta2 attribute-based mapping was supported via the System.Data.Linq namespace. If you then installed Beta2 and tried to compile your code you received a lot of compile errors. That is because attribute-based mapping is now supported via the System.Data.Linq.Mapping namespace. Next underneath the partial class of Forml add the following highlighted code namespace LINQ public partial class Form1 Form public Forml InitializeComponent private void Form1_Load object sender EventArgs e public class AdventureWorks DataContext public AdventureWorks string connection base connection public Table Contact Contacts Table Name Person.Contact public class Contact Column DbType int not null IsPrimaryKey true IsDbGenerated true public int ContactID Column DbType nvarchar 8 not null public string Title Column DbType nvarchar 50 not null public string FirstName Column DbType nvarchar 50 not null public string MiddleName 259 Part III LINQtoSQL Column DbType nvarchar 50 not null public string LastName Column DbType nvarchar 50 not null public string EmailAddress Column DbType int public int EmailPromotion Column DbType bit public byte NameStyle Column DbType varchar 40 public string PasswordHash Column DbType varchar 40 public string PasswordSalt The rest of this code should look familiar you have seen it throughout the last few chapters. Attributebased mapping is used to map a SQL Server database and table to a LINQ to SQL class. For purposes of this example create a small routine that will do a lot of the work for you. Add the following code after the Load event of Form1. The code will be explained shortly. private void InsertNames string firstName string title string emailAddr AdventureWorks db .