tailieunhanh - Programming LINQ,

The best way to write queres using LINQ to SQL is by having a DataContext-derived class in your code that exposes all the tables, stored procedures, and user-defined functions you need as properties of a class instance. You also need entity classes that are mapped to the database objects. As you have seen in previous chapters, this mapping can be made by using attributes to decorate classes or through an external XML mapping file. However, writing this information by hand is tedious and error-prone work. You need some tools to help you accomplish this work | . . . Microsoft Foreword by Luca Bolognese LINQ Principal Program Manager Microsoft Corporation Programming Microsoft LINQ Paolo Pialorsi Marco Russo Chapter 6 Tools for LINQ to SQL The best way to write queries using LINQ to SQL is by having a DataContext-derived class in your code that exposes all the tables stored procedures and user-defined functions you need as properties of a class instance. You also need entity classes that are mapped to the database objects. As you have seen in previous chapters this mapping can be made by using attributes to decorate classes or through an external XML mapping file. However writing this information by hand is tedious and error-prone work. You need some tools to help you accomplish this work. In this chapter you will learn about what file types are involved and what tools are available to automatically generate this information. The .NET Software Development Kit SDK includes a command-line tool named SQLMetal. Microsoft Visual Studio 2008 offers an integrated graphical tool named the Object Relational Designer. We will examine both tools from a practical point of view. Important In this chapter we use the version of the Northwind database that is included in the C samples provided with Visual Studio 2008. All the samples are contained in the Microsoft Visual Studio Samples 1033 file in your program files directory if you installed Visual Studio 2008. You can also download an updated version of these samples from http csharpsamples. File Types There are three types of files involved in LINQ to SQL entities and a mapping definition Database markup language .DBML Source code C or Visual Basic External mapping file XML A common mistake is the confusion between DBML and XML mapping files. At first sight these two files are similar but they are very different in their use and generation process. DBML Database Markup Language The DBML file contains a description of the LINQ to SQL .