In that same xml document youll also find this

Info icon This preview shows pages 610–612. Sign up to view the full content.

View Full Document Right Arrow Icon
see a simple XML representation of all the property values for the entity. In that same XML document, you’ll also find this element: <link rel=" SalesOrderHeaders" type="application/atom+xml;type=feed" title="SalesOrderHeaders" href="Customers(29531)/SalesOrderHeaders" /> This is how associations in the EDM show up—if an entity has related entities available through an association, it will offer a link to the URL on which those associations can be found. So as the href in this example shows, you can just stick SalesOrderHeaders on the end of the customer instance URL to get all the related orders for customer 29531, as in the following: 586 | Chapter 14: Databases
Image of page 610

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
(29531)/SalesOrderHeaders So you can see how joins across relationships turn into URLs, and also how simple key- based queries work. In fact, the URL syntax also supports more complex queries based on properties. For example, this returns all customers whose FirstName has the value Cory : 'Cory' (The %20 is how URLs represent spaces, so we’ve really just appended $filter=First Name eq 'Cory' to the URL.) The URL syntax also supports ordering and paging. Many standard LINQ operators are not supported, including grouping and joining. You don’t have to work directly with these URLs and XML documents—WCF Data Services includes a client-side component that supports LINQ. So you can run LINQ queries that will be converted into HTTP requests that use the URL structure you see here. We can demonstrate this by adding a new console application to the same solution as our web application. If we right-click on the console application’s References item in the Solution Explorer and select Add Service Reference, clicking Discover in the dialog that opens will show the WCF Data Service from the other project. Selecting this and clicking OK generates code to represent each entity type defined by the service. That enables us to write code such as Example 14-23 . Example 14-23. Client-side WCF Data Services code var ctx = new AdventureWorksLT2008Entities( new Uri(" ")); var customers = from customer in ctx.Customers where customer.FirstName == "Cory" select customer; foreach (Customer customer in customers) { Console.WriteLine(customer.CompanyName); } This looks superficially similar to the Entity Framework code we saw earlier—we still have an object context, for example. Visual Studio generated the Adventure WorksLT2008Entities class when we imported the service reference, and it derives from DataServiceContext . It’s slightly different from the EF context—it’s not disposable, for one thing. (That’s why there’s no using statement here—this object context doesn’t implement IDisposable .) And it’s a lot simpler—it doesn’t do any change tracking.
Image of page 611
Image of page 612
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern