Tham khảo tài liệu 'pro entity framework 4 0 depositfiles_2', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | C H A P T E R 4 Querying the EDM You have spent the previous two chapters creating and exploring an Entity Data Model. Chapter 2 discussed the different ways an EDM can be created and Chapter 3 explored the many facets of the EDM both internally and externally. It is now finally time to write some code. This chapter will discuss how to write queries against the EDM by using the LINQ-to-Entities syntax and the Entity SQL syntax both provided by the Entity Framework. This chapter will also discuss the difference between query syntax and method syntax and when you might use one over the other. We ll also spend a few pages discussing how queries are executed so that you can write effective queries for optimal performance. We won t go too deep in this chapter since we ll save the more advanced topics for later. The important thing this chapter will do will be to build a foundation you can use for writing and optimizing queries. Querying with the Entity Framework The key to remember when working and querying with the Entity Framework is that you are querying a data model not directly against a database. Over the last couple of chapters you have created several EDMs and in this chapter you are going to query against the EDM. This is much different than querying directly against a database for several reasons. First the syntax is different. Instead of writing T-SQL queries you will use LINQ to Entities or Entity SQL to construct and execute queries. Second when you query the EDM you are letting the Entity Framework do a lot of the work for you such as processing your queries and handling results. The Entity Framework employs the providers to handle query operations. Specifically the is utilized to turn your query into something the SQL Server database engine will understand. On the return side this same provider will do the work of translating the results into objects that your application can work with. I know by now you are itching to .