MSDN Magazine - July 2008 - (Page 61) Cities 1 Now that the initial setup is complete, let’s move ahead and add the cities-served functionality. Adding a City As mentioned earlier, Contoso Classifieds places each city’s listings in its own from e in entities where e["CategoryID"] == "For Sale" select e authority, which enables you to choose the datacenter it is hosted in. (While that Figure 5 Entity Data Model Used by the App Notice I say flex property. As previously feature is not currently supported in the beta of SSDS, it will be mentioned, entities in a container must have unique IDs that will supported by the time the product is released.) limit you from using the distinguished system property ID. Also The code for adding the city is similar to the code used for the notice the query syntax I have issued. SSDS uses a LINQ-like queinitial setup. Using the SOAP proxy, set the credentials, create an ry syntax, which should look familiar to most developers who use empty scope, set the authority ID, and issue the create: the .NET Framework. SSDSClient.Authority cityAuth = If you look back at the administrative application shown in Fignew SSDSClient.Authority(); ure 4, you will notice a tree view that represents the listing catecityAuth.Id = cityAuthorityName; gories and two textboxes for adding category headers and listing ssdsProxy.Create(serviceScope, cityAuth); categories. Let’s dive into the implementation behind adding a Now that the new city authority is created, add a pointer entity to category header. the Cities container in the main contosoclassifieds authority: As with the previous code, you use the SitkaSOAPServiceClient, serviceScope.AuthorityId = "contosoclassifieds"; set the credentials, and set the scope to the contosoclassifieds auserviceScope.ContainerId = "Cities"; thority and the Categories container. Now all you need to do is //Create the City Entity, and set its properties appropriately create the entity: SSDSClient.Entity cityEntity = new SSDSClient.Entity(); cityEntity.Id = cityAuthorityName; cityEntity.Kind = "CityServed"; cityEntity.Properties = new Dictionary (); cityEntity.Properties["AuthorityUri"] = string.Format("{0}.data.data.beta.mssds.com/v1/", cityAuthorityName); cityEntity.Properties["Name"] = txtCity.Text; //Issue the create to SSDS ssdsProxy.Create(serviceScope, cityEntity); SSDSClient.Scope serviceScope = new SSDSClient.Scope(); serviceScope.AuthorityId = "contosoclassifieds"; serviceScope.ContainerId = "Categories"; SSDSClient.Entity categoryHeaderEntity = new SSDSClient.Entity(); categoryHeaderEntity.Id = CategoryID; categoryHeaderEntity.Kind = "Category"; tities can have the same Kind, that does not force the entities to be homogeneous. The entity can have whatever shape you would like. A better approach to this scenario might be to have two different entity Kinds, Category and Listing Category, and to have a flex property of CategoryID in all entities. That would allow you to issue a query such as: Let’s recap for a moment. I’ve created a main contosoclassifieds authority that holds all of the systemwide data. In that authority, there is a Cities container that has an entity for each city the application will serve. That entity contains the display name of the city, along with a pointer to the authority that contains all the listings. You can also add a single flex property that will contain the category name. Notice that this only adds a single property to the flex properties collection: categoryHeaderEntity.Properties = new Dictionary (); categoryHeaderEntity.Properties["CategoryName"] = CategoryName; Adding Categories Figure 6 Adding Flex Properties //Determine whether this is the first listing //category being added to this header if (categoryEntity.Properties.Count > 2) { propCount = ((categoryEntity.Properties.Count - 1) / 2); propCount++; } else { propCount = 1; } //Create the FlexProperties for the new listing category string listingIdPropName = string.Format ("ListingCategoryID{0}", propCount); string listingNamePropName = string.Format ("ListingCategoryName{0}", propCount); categoryEntity.Properties[listingIdPropName] = ListingCategoryID; categoryEntity.Properties[listingNamePropName] = ListingCategoryName; //Issue the update to SSDS ssdsProxy.Update(serviceScope, categoryEntity); Up to this point, you’ve just added authorities, containers, and entities. The next step is to implement the listing categories feature. To do so involves using the query, update, and delete functionality of SSDS. Contoso Classifieds will support a category header, with sub categories below it to hold the actual postings from users. If you were to use a relational model for this data, you would typically use a header/line pattern for the data. The flexible entity data model used by SSDS, however, allows your data to take whatever shape you like. In the case of the Contoso Classifieds application, I chose to use a single entity to represent each category header and all the subcategories that belong to it (see Figure 5). Please note that I am using this pattern to simply show the flexible nature of an entity and to illustrate that, although multiple enmsdnmagazine.com July 2008 61 http://msdnmagazine.com
Table of Contents Feed for the Digital Edition of MSDN Magazine - July 2008 MSDN Magazine - July 2008 Contents Toolbox CLR Inside Out Flex Your Data Data Points Advanced Basics Office Space Cutting Edge Data Services ADO.NET Data and WPF Transactions WCF P2P Test Run Security Briefs Foundations .NET Matters {End Bracket} MSDN Magazine - July 2008 MSDN Magazine - July 2008 - (Page Intro) MSDN Magazine - July 2008 - Contents (Page Cover1) MSDN Magazine - July 2008 - Contents (Page Cover2) MSDN Magazine - July 2008 - Contents (Page 1) MSDN Magazine - July 2008 - Contents (Page 2) MSDN Magazine - July 2008 - Contents (Page 3) MSDN Magazine - July 2008 - Contents (Page 4) MSDN Magazine - July 2008 - Contents (Page 5) MSDN Magazine - July 2008 - Contents (Page 6) MSDN Magazine - July 2008 - Contents (Page 7) MSDN Magazine - July 2008 - Contents (Page 8) MSDN Magazine - July 2008 - Contents (Page 9) MSDN Magazine - July 2008 - Contents (Page 10) MSDN Magazine - July 2008 - Toolbox (Page 11) MSDN Magazine - July 2008 - Toolbox (Page 12) MSDN Magazine - July 2008 - Toolbox (Page 13) MSDN Magazine - July 2008 - Toolbox (Page 14) MSDN Magazine - July 2008 - Toolbox (Page 15) MSDN Magazine - July 2008 - Toolbox (Page 16) MSDN Magazine - July 2008 - CLR Inside Out (Page 17) MSDN Magazine - July 2008 - CLR Inside Out (Page 18) MSDN Magazine - July 2008 - CLR Inside Out (Page 19) MSDN Magazine - July 2008 - CLR Inside Out (Page 20) MSDN Magazine - July 2008 - CLR Inside Out (Page 21) MSDN Magazine - July 2008 - CLR Inside Out (Page 22) MSDN Magazine - July 2008 - CLR Inside Out (Page 23) MSDN Magazine - July 2008 - CLR Inside Out (Page 24) MSDN Magazine - July 2008 - Data Points (Page 25) MSDN Magazine - July 2008 - Data Points (Page 26) MSDN Magazine - July 2008 - Data Points (Page 27) MSDN Magazine - July 2008 - Data Points (Page 28) MSDN Magazine - July 2008 - Data Points (Page 29) MSDN Magazine - July 2008 - Data Points (Page 30) MSDN Magazine - July 2008 - Data Points (Page 31) MSDN Magazine - July 2008 - Data Points (Page 32) MSDN Magazine - July 2008 - Data Points (Page 33) MSDN Magazine - July 2008 - Data Points (Page 34) MSDN Magazine - July 2008 - Advanced Basics (Page 35) MSDN Magazine - July 2008 - Advanced Basics (Page 36) MSDN Magazine - July 2008 - Advanced Basics (Page 37) MSDN Magazine - July 2008 - Advanced Basics (Page 38) MSDN Magazine - July 2008 - Advanced Basics (Page 39) MSDN Magazine - July 2008 - Advanced Basics (Page 40) MSDN Magazine - July 2008 - Advanced Basics (Page 41) MSDN Magazine - July 2008 - Advanced Basics (Page 42) MSDN Magazine - July 2008 - Office Space (Page 43) MSDN Magazine - July 2008 - Office Space (Page 44) MSDN Magazine - July 2008 - Office Space (Page 45) MSDN Magazine - July 2008 - Office Space (Page 46) MSDN Magazine - July 2008 - Office Space (Page 47) MSDN Magazine - July 2008 - Office Space (Page 48) MSDN Magazine - July 2008 - Office Space (Page 49) MSDN Magazine - July 2008 - Office Space (Page 50) MSDN Magazine - July 2008 - Cutting Edge (Page 51) MSDN Magazine - July 2008 - Cutting Edge (Page 52) MSDN Magazine - July 2008 - Cutting Edge (Page 53) MSDN Magazine - July 2008 - Cutting Edge (Page 54) MSDN Magazine - July 2008 - Cutting Edge (Page 55) MSDN Magazine - July 2008 - Cutting Edge (Page 56) MSDN Magazine - July 2008 - Cutting Edge (Page 57) MSDN Magazine - July 2008 - Data Services (Page 58) MSDN Magazine - July 2008 - Data Services (Page 59) MSDN Magazine - July 2008 - Data Services (Page 60) MSDN Magazine - July 2008 - Data Services (Page 61) MSDN Magazine - July 2008 - Data Services (Page 62) MSDN Magazine - July 2008 - Data Services (Page 63) MSDN Magazine - July 2008 - Data Services (Page 64) MSDN Magazine - July 2008 - Data Services (Page 65) MSDN Magazine - July 2008 - Data Services (Page 66) MSDN Magazine - July 2008 - Data Services (Page 67) MSDN Magazine - July 2008 - Data Services (Page 68) MSDN Magazine - July 2008 - Data Services (Page 69) MSDN Magazine - July 2008 - ADO.NET (Page 70) MSDN Magazine - July 2008 - ADO.NET (Page 71) MSDN Magazine - July 2008 - ADO.NET (Page 72) MSDN Magazine - July 2008 - ADO.NET (Page 73) MSDN Magazine - July 2008 - ADO.NET (Page 74) MSDN Magazine - July 2008 - ADO.NET (Page 75) MSDN Magazine - July 2008 - ADO.NET (Page 76) MSDN Magazine - July 2008 - ADO.NET (Page 77) MSDN Magazine - July 2008 - Data and WPF (Page 78) MSDN Magazine - July 2008 - Data and WPF (Page 79) MSDN Magazine - July 2008 - Data and WPF (Page 80) MSDN Magazine - July 2008 - Data and WPF (Page 81) MSDN Magazine - July 2008 - Data and WPF (Page 82) MSDN Magazine - July 2008 - Data and WPF (Page 83) MSDN Magazine - July 2008 - Data and WPF (Page 84) MSDN Magazine - July 2008 - Data and WPF (Page 85) MSDN Magazine - July 2008 - Data and WPF (Page 86) MSDN Magazine - July 2008 - Data and WPF (Page 87) MSDN Magazine - July 2008 - Data and WPF (Page 88) MSDN Magazine - July 2008 - Data and WPF (Page 89) MSDN Magazine - July 2008 - Data and WPF (Page 90) MSDN Magazine - July 2008 - Transactions (Page 91) MSDN Magazine - July 2008 - Transactions (Page 92) MSDN Magazine - July 2008 - Transactions (Page 93) MSDN Magazine - July 2008 - Transactions (Page 94) MSDN Magazine - July 2008 - Transactions (Page 95) MSDN Magazine - July 2008 - Transactions (Page 96) MSDN Magazine - July 2008 - Transactions (Page 97) MSDN Magazine - July 2008 - Transactions (Page 98) MSDN Magazine - July 2008 - Transactions (Page 99) MSDN Magazine - July 2008 - Transactions (Page 100) MSDN Magazine - July 2008 - Transactions (Page 101) MSDN Magazine - July 2008 - Transactions (Page 102) MSDN Magazine - July 2008 - Transactions (Page 103) MSDN Magazine - July 2008 - Transactions (Page 104) MSDN Magazine - July 2008 - WCF P2P (Page 105) MSDN Magazine - July 2008 - WCF P2P (Page 106) MSDN Magazine - July 2008 - WCF P2P (Page 107) MSDN Magazine - July 2008 - WCF P2P (Page 108) MSDN Magazine - July 2008 - WCF P2P (Page 109) MSDN Magazine - July 2008 - WCF P2P (Page 110) MSDN Magazine - July 2008 - Test Run (Page 111) MSDN Magazine - July 2008 - Test Run (Page 112) MSDN Magazine - July 2008 - Test Run (Page 113) MSDN Magazine - July 2008 - Test Run (Page 114) MSDN Magazine - July 2008 - Test Run (Page 115) MSDN Magazine - July 2008 - Test Run (Page 116) MSDN Magazine - July 2008 - Security Briefs (Page 117) MSDN Magazine - July 2008 - Security Briefs (Page 118) MSDN Magazine - July 2008 - Security Briefs (Page 119) MSDN Magazine - July 2008 - Security Briefs (Page 120) MSDN Magazine - July 2008 - Security Briefs (Page 121) MSDN Magazine - July 2008 - Security Briefs (Page 122) MSDN Magazine - July 2008 - Foundations (Page 123) MSDN Magazine - July 2008 - Foundations (Page 124) MSDN Magazine - July 2008 - Foundations (Page 125) MSDN Magazine - July 2008 - Foundations (Page 126) MSDN Magazine - July 2008 - Foundations (Page 127) MSDN Magazine - July 2008 - Foundations (Page 128) MSDN Magazine - July 2008 - Foundations (Page 129) MSDN Magazine - July 2008 - Foundations (Page 130) MSDN Magazine - July 2008 - .NET Matters (Page 131) MSDN Magazine - July 2008 - .NET Matters (Page 132) MSDN Magazine - July 2008 - .NET Matters (Page 133) MSDN Magazine - July 2008 - .NET Matters (Page 134) MSDN Magazine - July 2008 - .NET Matters (Page 135) MSDN Magazine - July 2008 - {End Bracket} (Page 136) MSDN Magazine - July 2008 - {End Bracket} (Page Cover3) MSDN Magazine - July 2008 - {End Bracket} (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.