├── .gitattributes
├── .gitignore
├── CONTRIBUTING.md
├── GetStarted.sln
├── LICENSE
├── README.md
├── media
└── image1.png
└── src
├── App.config
├── GetStarted.csproj
├── Program.cs
├── Properties
└── AssemblyInfo.cs
└── packages.config
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Visual Studio
3 | #################
4 |
5 | ## Ignore Visual Studio temporary files, build results, and
6 | ## files generated by popular Visual Studio add-ons.
7 |
8 | # User-specific files
9 | *.suo
10 | *.user
11 | *.sln.docstates
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Rr]elease/
16 | x64/
17 | build/
18 | [Bb]in/
19 | [Oo]bj/
20 |
21 | # Debug.config files
22 | *.Debug.config
23 | *.Release.config
24 |
25 | # ReSharper is a .NET coding add-in
26 | _ReSharper*/
27 | *.[Rr]e[Ss]harper
28 |
29 | # Publish Web Output
30 | *.Publish.xml
31 | *.pubxml
32 |
33 | # NuGet Packages Directory
34 | packages/
35 | .nuget/
36 |
37 | # Windows Azure Build Output
38 | csx
39 | *.build.csdef
40 |
41 | # RIA/Silverlight projects
42 | Generated_Code/
43 |
44 | # Backup & report files from converting an old project file to a newer
45 | # Visual Studio version. Backup files are not needed, because we have git ;-)
46 | _UpgradeReport_Files/
47 | Backup*/
48 | UpgradeLog*.XML
49 | UpgradeLog*.htm
50 |
51 |
52 | #############
53 | ## Windows detritus
54 | #############
55 |
56 | # Windows image file caches
57 | Thumbs.db
58 | ehthumbs.db
59 |
60 | # Folder config file
61 | Desktop.ini
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to Azure samples
2 |
3 | Thank you for your interest in contributing to Azure samples!
4 |
5 | ## Ways to contribute
6 |
7 | You can contribute to [Azure samples](https://azure.microsoft.com/documentation/samples/) in a few different ways:
8 |
9 | - Submit feedback on [this sample page](https://azure.microsoft.com/documentation/samples/documentdb-dotnet-getting-started/) whether it was helpful or not.
10 | - Submit issues through [issue tracker](https://github.com/Azure-Samples/documentdb-dotnet-getting-started/issues) on GitHub. We are actively monitoring the issues and improving our samples.
11 | - If you wish to make code changes to samples, or contribute something new, please follow the [GitHub Forks / Pull requests model](https://help.github.com/articles/fork-a-repo/): Fork the sample repo, make the change and propose it back by submitting a pull request.
--------------------------------------------------------------------------------
/GetStarted.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetStarted", "src\GetStarted.csproj", "{2A834C4E-055B-4C5E-BA76-D9438D98AC42}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {2A834C4E-055B-4C5E-BA76-D9438D98AC42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {2A834C4E-055B-4C5E-BA76-D9438D98AC42}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {2A834C4E-055B-4C5E-BA76-D9438D98AC42}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {2A834C4E-055B-4C5E-BA76-D9438D98AC42}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Microsoft Corporation
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | services: cosmos-db
3 | platforms: dotnet
4 | author: andrewhoh
5 | ---
6 |
7 | # Developing a .NET console app using Azure Cosmos DB
8 | This sample shows you how to use the Azure Cosmos DB service to store and access data from a .NET console application.
9 |
10 | 
11 |
12 | For a complete end-to-end walkthrough of creating this application, please refer to the [full tutorial on the Azure Cosmos DB documentation page](https://docs.microsoft.com/azure/cosmos-db/sql-api-get-started).
13 |
14 | ## Running this sample
15 |
16 | 1. Before you can run this sample, you must have the following prerequisites:
17 | - An active Azure Cosmos DB account - If you don't have an account, refer to the [Create a database account](https://docs.microsoft.com/azure/cosmos-db/create-sql-api-dotnet#create-a-database-account) article.
18 | - Visual Studio 2013 (or higher).
19 |
20 | 2.Clone this repository using Git for Windows (http://www.git-scm.com/), or download the zip file.
21 |
22 | 3.From Visual Studio, open the **GetStarted.sln** file from the root directory.
23 |
24 | 4.In Visual Studio Build menu, select **Build Solution** (or Press F6).
25 |
26 | 5.Retrieve the URI and PRIMARY KEY (or SECONDARY KEY) values from the Keys blade of your Azure Cosmos DB account in the Azure portal. For more information on obtaining endpoint & keys for your Azure Cosmos DB account refer to [View, copy, and regenerate access keys and passwords](https://docs.microsoft.com/en-us/azure/cosmos-db/manage-account#keys)
27 |
28 | If you don't have an account, see [Create a database account](https://docs.microsoft.com/azure/cosmos-db/create-sql-api-dotnet#create-a-database-account) to set one up.
29 |
30 | 6.In the **App.config** file, located in the src directory, find **endpoint** and **authKey** and replace the placeholder values with the values obtained for your account.
31 |
32 |
33 |
34 |
35 | 7.You can now run and debug the application locally by pressing **F5** in Visual Studio.
36 |
37 | ## About the code
38 | The code included in this sample is intended to get you quickly started with a .NET console application that connects to Azure Cosmos Db.
39 |
40 | ## More information
41 |
42 | - [Azure Cosmos DB Documentation](https://docs.microsoft.com/azure/cosmos-db/index)
43 | - [Azure Cosmos DB .NET SDK for SQL API](https://docs.microsoft.com/azure/cosmos-db/sql-api-sdk-dotnet)
44 | - [Azure Cosmos DB .NET SDK Reference Documentation](https://docs.microsoft.com/dotnet/api/overview/azure/cosmosdb?view=azure-dotnet)
45 |
--------------------------------------------------------------------------------
/media/image1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/documentdb-dotnet-getting-started/b61c0e8bb0d5609064c3f3effed1551d22fc8673/media/image1.png
--------------------------------------------------------------------------------
/src/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/GetStarted.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {2A834C4E-055B-4C5E-BA76-D9438D98AC42}
8 | Exe
9 | Properties
10 | DocDBGetStarted
11 | DocDBGetStarted
12 | v4.5
13 | 512
14 | C:\Users\anhoh\Desktop\
15 | true
16 | Disk
17 | false
18 | Foreground
19 | 7
20 | Days
21 | false
22 | false
23 | true
24 | 0
25 | 1.0.0.0
26 | false
27 | false
28 | true
29 | true
30 | ..\
31 |
32 |
33 |
34 |
35 |
36 | AnyCPU
37 | true
38 | full
39 | false
40 | bin\Debug\
41 | DEBUG;TRACE
42 | prompt
43 | 4
44 | false
45 |
46 |
47 | AnyCPU
48 | pdbonly
49 | true
50 | bin\Release\
51 | TRACE
52 | prompt
53 | 4
54 | false
55 |
56 |
57 | $([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\..\packages\SlowCheetah.2.5.14\tools\))
58 | true
59 | $([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\Properties\SlowCheetah\SlowCheetah.Transforms.targets ))
60 | $(SlowCheetah_NuGetImportPath)
61 |
62 |
63 | 2A1DE3FF5C45B89F0998B10DD5E00E6A6E93FFAE
64 |
65 |
66 | GetStarted_TemporaryKey.pfx
67 |
68 |
69 | true
70 |
71 |
72 | false
73 |
74 |
75 |
76 | ..\packages\Microsoft.Azure.DocumentDB.1.21.1\lib\net45\Microsoft.Azure.Documents.Client.dll
77 | True
78 |
79 |
80 | ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll
81 | True
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | Designer
99 | true
100 |
101 |
102 | App.config
103 | True
104 |
105 |
106 | App.config
107 | True
108 |
109 |
110 |
111 |
112 |
113 | False
114 | Microsoft .NET Framework 4.5 %28x86 and x64%29
115 | true
116 |
117 |
118 | False
119 | .NET Framework 3.5 SP1 Client Profile
120 | false
121 |
122 |
123 | False
124 | .NET Framework 3.5 SP1
125 | false
126 |
127 |
128 |
129 |
130 | ..\packages\Microsoft.Azure.DocumentDB.1.0.0\lib\net40\Microsoft.Azure.Documents.Client.dll
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
143 |
144 |
145 |
146 |
153 |
--------------------------------------------------------------------------------
/src/Program.cs:
--------------------------------------------------------------------------------
1 | //---------------------------------------------------------------------------------
2 | //
3 | // Microsoft (R) Azure SDK
4 | // Software Development Kit
5 | //
6 | // Copyright (c) Microsoft Corporation. All rights reserved.
7 | //
8 | // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
9 | // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
10 | // OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
11 | //
12 | //---------------------------------------------------------------------------------
13 |
14 | namespace DocumentDB.GetStarted
15 | {
16 | using System;
17 | using System.Linq;
18 | using System.Threading.Tasks;
19 | using System.Net;
20 | using System.Configuration;
21 | using Microsoft.Azure.Documents;
22 | using Microsoft.Azure.Documents.Client;
23 | using Newtonsoft.Json;
24 |
25 | ///
26 | /// This get-started sample demonstrates the creation of resources and execution of simple queries.
27 | ///
28 | public class Program
29 | {
30 | ///
31 | /// The Azure DocumentDB endpoint for running this GetStarted sample.
32 | ///
33 | private static readonly string EndpointUri = ConfigurationManager.AppSettings["EndPointUrl"];
34 |
35 | ///
36 | /// The primary key for the Azure DocumentDB account.
37 | ///
38 | private static readonly string PrimaryKey = ConfigurationManager.AppSettings["PrimaryKey"];
39 |
40 | ///
41 | /// The DocumentDB client instance.
42 | ///
43 | private DocumentClient client;
44 |
45 | ///
46 | /// The main method for the demo
47 | ///
48 | /// Command line arguments
49 | static void Main(string[] args)
50 | {
51 | try
52 | {
53 | Program p = new Program();
54 | p.GetStartedDemo().Wait();
55 | }
56 | catch (DocumentClientException de)
57 | {
58 | Exception baseException = de.GetBaseException();
59 | Console.WriteLine("{0} error occurred: {1}", de.StatusCode, de);
60 | }
61 | catch (Exception e)
62 | {
63 | Console.WriteLine("Error: {0}", e);
64 | }
65 | finally
66 | {
67 | Console.WriteLine("End of demo, press any key to exit.");
68 | Console.ReadKey();
69 | }
70 | }
71 |
72 | ///
73 | /// Run the get started demo for Azure Cosmos DB. This creates a database, collection, two documents, executes a simple query
74 | /// and cleans up.
75 | ///
76 | /// The Task for asynchronous completion.
77 | private async Task GetStartedDemo()
78 | {
79 | // Create a new instance of the DocumentClient
80 | this.client = new DocumentClient(new Uri(EndpointUri), PrimaryKey);
81 |
82 | Database databaseInfo = new Database { Id = "FamilyDB_og" };
83 | await this.client.CreateDatabaseIfNotExistsAsync(databaseInfo);
84 |
85 | DocumentCollection collectionInfo = new DocumentCollection();
86 | collectionInfo.Id = "FamilyCollection_og";
87 |
88 | // We choose LastName as the partition key since we're storing family information. Data is seamlessly scaled out based on the last name of
89 | // the inserted entity.
90 | collectionInfo.PartitionKey.Paths.Add("/LastName");
91 |
92 | // Optionally, you can configure the indexing policy of a collection. Here we configure collections for maximum query flexibility
93 | // including string range queries.
94 | collectionInfo.IndexingPolicy = new IndexingPolicy(new RangeIndex(DataType.String) { Precision = -1 });
95 |
96 | // Collections can be reserved with throughput specified in request units/second. 1 RU is a normalized request equivalent to the read
97 | // of a 1KB document. Here we create a collection with 400 RU/s.
98 | await this.client.CreateDocumentCollectionIfNotExistsAsync(
99 | UriFactory.CreateDatabaseUri(databaseInfo.Id),
100 | collectionInfo,
101 | new RequestOptions { OfferThroughput = 400 });
102 |
103 | // Insert a document, here we create a Family object
104 | Family andersenFamily = new Family
105 | {
106 | Id = "Andersen.1",
107 | LastName = "Andersen",
108 | Parents = new Parent[]
109 | {
110 | new Parent { FirstName = "Thomas" },
111 | new Parent { FirstName = "Mary Kay" }
112 | },
113 | Children = new Child[]
114 | {
115 | new Child
116 | {
117 | FirstName = "Henriette Thaulow",
118 | Gender = "female",
119 | Grade = 5,
120 | Pets = new Pet[]
121 | {
122 | new Pet { GivenName = "Fluffy" }
123 | }
124 | }
125 | },
126 | Address = new Address { State = "WA", County = "King", City = "Seattle" },
127 | IsRegistered = true
128 | };
129 |
130 | await this.CreateFamilyDocumentIfNotExists("FamilyDB_og", "FamilyCollection_og", andersenFamily);
131 |
132 | Family wakefieldFamily = new Family
133 | {
134 | Id = "Wakefield.7",
135 | LastName = "Wakefield",
136 | Parents = new Parent[]
137 | {
138 | new Parent { FamilyName = "Wakefield", FirstName = "Robin" },
139 | new Parent { FamilyName = "Miller", FirstName = "Ben" }
140 | },
141 | Children = new Child[]
142 | {
143 | new Child
144 | {
145 | FamilyName = "Merriam",
146 | FirstName = "Jesse",
147 | Gender = "female",
148 | Grade = 8,
149 | Pets = new Pet[]
150 | {
151 | new Pet { GivenName = "Goofy" },
152 | new Pet { GivenName = "Shadow" }
153 | }
154 | },
155 | new Child
156 | {
157 | FamilyName = "Miller",
158 | FirstName = "Lisa",
159 | Gender = "female",
160 | Grade = 1
161 | }
162 | },
163 | Address = new Address { State = "NY", County = "Manhattan", City = "NY" },
164 | IsRegistered = false
165 | };
166 |
167 | await this.CreateFamilyDocumentIfNotExists("FamilyDB_og", "FamilyCollection_og", wakefieldFamily);
168 |
169 | this.ExecuteSimpleQuery("FamilyDB_og", "FamilyCollection_og");
170 |
171 | // Update the Grade of the Andersen Family child
172 | andersenFamily.Children[0].Grade = 6;
173 |
174 | await this.ReplaceFamilyDocument("FamilyDB_og", "FamilyCollection_og", andersenFamily);
175 |
176 | this.ExecuteSimpleQuery("FamilyDB_og", "FamilyCollection_og");
177 |
178 | // Delete the document
179 | await this.DeleteFamilyDocument("FamilyDB_og", "FamilyCollection_og", "Andersen", "Andersen.1");
180 |
181 | // Clean up/delete the database and client
182 | await this.client.DeleteDatabaseAsync(UriFactory.CreateDatabaseUri("FamilyDB_og"));
183 | }
184 |
185 | ///
186 | /// Create the Family document in the collection if another by the same partition key/item key doesn't already exist.
187 | ///
188 | /// The name/ID of the database.
189 | /// The name/ID of the collection.
190 | /// The family document to be created.
191 | /// The Task for asynchronous execution.
192 | private async Task CreateFamilyDocumentIfNotExists(string databaseName, string collectionName, Family family)
193 | {
194 | try
195 | {
196 | await this.client.ReadDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collectionName, family.Id), new RequestOptions { PartitionKey = new PartitionKey(family.LastName) });
197 | this.WriteToConsoleAndPromptToContinue("Found {0}", family.Id);
198 | }
199 | catch (DocumentClientException de)
200 | {
201 | if (de.StatusCode == HttpStatusCode.NotFound)
202 | {
203 | await this.client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), family);
204 | this.WriteToConsoleAndPromptToContinue("Created Family {0}", family.Id);
205 | }
206 | else
207 | {
208 | throw;
209 | }
210 | }
211 | }
212 |
213 | ///
214 | /// Execute a simple query using LINQ and SQL. Here we filter using the "LastName" property.
215 | ///
216 | /// The name/ID of the database.
217 | /// The name/ID of the collection.
218 | private void ExecuteSimpleQuery(string databaseName, string collectionName)
219 | {
220 | // Set some common query options
221 | FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1 };
222 |
223 | // Run a simple query via LINQ. DocumentDB indexes all properties, so queries can be completed efficiently and with low latency.
224 | // Here we find the Andersen family via its LastName
225 | IQueryable familyQuery = this.client.CreateDocumentQuery(
226 | UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), queryOptions)
227 | .Where(f => f.LastName == "Andersen");
228 |
229 | // The query is executed synchronously here, but can also be executed asynchronously via the IDocumentQuery interface
230 | Console.WriteLine("Running LINQ query...");
231 | foreach (Family family in familyQuery)
232 | {
233 | Console.WriteLine("\tRead {0}", family);
234 | }
235 |
236 | // Now execute the same query via direct SQL
237 | IQueryable familyQueryInSql = this.client.CreateDocumentQuery(
238 | UriFactory.CreateDocumentCollectionUri(databaseName, collectionName),
239 | "SELECT * FROM Family WHERE Family.LastName = 'Andersen'",
240 | queryOptions);
241 |
242 | Console.WriteLine("Running direct SQL query...");
243 | foreach (Family family in familyQueryInSql)
244 | {
245 | Console.WriteLine("\tRead {0}", family);
246 | }
247 |
248 | Console.WriteLine("Press any key to continue ...");
249 | Console.ReadKey();
250 | }
251 |
252 | ///
253 | /// Replace the Family document in the collection.
254 | ///
255 | /// The name/ID of the database.
256 | /// The name/ID of the collection.
257 | /// The family document to be replaced.
258 | /// The Task for asynchronous execution.
259 | private async Task ReplaceFamilyDocument(string databaseName, string collectionName, Family updatedFamily)
260 | {
261 | await this.client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collectionName, updatedFamily.Id), updatedFamily);
262 | this.WriteToConsoleAndPromptToContinue("Replaced Family [{0},{1}]", updatedFamily.LastName, updatedFamily.Id);
263 | }
264 |
265 | ///
266 | /// Delete the Family document in the collection.
267 | ///
268 | /// The name/ID of the database.
269 | /// The name/ID of the collection.
270 | /// The partition key of the document.
271 | /// The document key of the document.
272 | /// The Task for asynchronous execution.
273 | private async Task DeleteFamilyDocument(string databaseName, string collectionName, string partitionKey, string documentKey)
274 | {
275 | await this.client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collectionName, documentKey), new RequestOptions { PartitionKey = new PartitionKey(partitionKey) });
276 | Console.WriteLine("Deleted Family [{0},{1}]", partitionKey, documentKey);
277 | }
278 |
279 | ///
280 | /// Write to the console, and prompt to continue.
281 | ///
282 | /// The string to be displayed.
283 | /// Optional arguments.
284 | private void WriteToConsoleAndPromptToContinue(string format, params object[] args)
285 | {
286 | Console.WriteLine(format, args);
287 | Console.WriteLine("Press any key to continue ...");
288 | Console.ReadKey();
289 | }
290 |
291 | ///
292 | /// A Family class, e.g. storing census data about families within the United States. We use this data model throughout the
293 | /// sample to show how you can store objects within your application logic directly as JSON within Azure DocumentDB.
294 | ///
295 | public class Family
296 | {
297 | [JsonProperty(PropertyName = "id")]
298 | public string Id { get; set; }
299 |
300 | public string LastName { get; set; }
301 |
302 | public Parent[] Parents { get; set; }
303 |
304 | public Child[] Children { get; set; }
305 |
306 | public Address Address { get; set; }
307 |
308 | public bool IsRegistered { get; set; }
309 |
310 | public override string ToString()
311 | {
312 | return JsonConvert.SerializeObject(this);
313 | }
314 | }
315 |
316 | ///
317 | /// A parent class used within Family
318 | ///
319 | public class Parent
320 | {
321 | public string FamilyName { get; set; }
322 |
323 | public string FirstName { get; set; }
324 | }
325 |
326 | ///
327 | /// A child class used within Family
328 | ///
329 | public class Child
330 | {
331 | public string FamilyName { get; set; }
332 |
333 | public string FirstName { get; set; }
334 |
335 | public string Gender { get; set; }
336 |
337 | public int Grade { get; set; }
338 |
339 | public Pet[] Pets { get; set; }
340 | }
341 |
342 | ///
343 | /// A pet class that belongs to a Child
344 | ///
345 | public class Pet
346 | {
347 | public string GivenName { get; set; }
348 | }
349 |
350 | ///
351 | /// An address class containing data attached to a Family.
352 | ///
353 | public class Address
354 | {
355 | public string State { get; set; }
356 |
357 | public string County { get; set; }
358 |
359 | public string City { get; set; }
360 | }
361 | }
362 | }
363 |
--------------------------------------------------------------------------------
/src/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("documentdb-net-getting-started")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("documentdb-net-getting-started")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("924fb665-a025-4b38-a92a-ca3dae3de12f")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------