Skip to content

Commit 159bf8f

Browse files
author
Ryan CrawCour
committed
Merge pull request Azure#54 from AndrewHoh/master
Changes to getting started
2 parents b8d4ca8 + cee12c6 commit 159bf8f

File tree

4 files changed

+41
-73
lines changed

4 files changed

+41
-73
lines changed

tutorials/get-started/src/App.config

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@
44
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
55
</startup>
66
<appSettings>
7-
<add key="EndPointUrl" value="~your documentdb enpoint here~" />
7+
<add key="EndPointUrl" value="~your DocumentDB endpoint here~" />
88
<add key="AuthorizationKey" value="~your auth key here~" />
99
</appSettings>
10-
<runtime>
11-
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
12-
<dependentAssembly>
13-
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
14-
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
15-
</dependentAssembly>
16-
</assemblyBinding>
17-
</runtime>
1810
</configuration>

tutorials/get-started/src/GetStarted.csproj

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@
7070
<SignManifests>false</SignManifests>
7171
</PropertyGroup>
7272
<ItemGroup>
73-
<Reference Include="Microsoft.Azure.Documents.Client">
74-
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.0.0\lib\net40\Microsoft.Azure.Documents.Client.dll</HintPath>
75-
<Private>True</Private>
73+
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
74+
<SpecificVersion>False</SpecificVersion>
75+
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.4.1\lib\net40\Microsoft.Azure.Documents.Client.dll</HintPath>
76+
</Reference>
77+
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
78+
<HintPath>..\packages\Newtonsoft.Json.5.0.7\lib\net45\Newtonsoft.Json.dll</HintPath>
7679
</Reference>
7780
<Reference Include="System" />
7881
<Reference Include="System.Configuration" />
@@ -124,10 +127,6 @@
124127
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.0.0\lib\net40\Microsoft.Azure.Documents.Client.dll</HintPath>
125128
</Reference>
126129
<Reference Include="Microsoft.CSharp" />
127-
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
128-
<SpecificVersion>False</SpecificVersion>
129-
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
130-
</Reference>
131130
<Reference Include="System" />
132131
<Reference Include="System.Configuration" />
133132
<Reference Include="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />

tutorials/get-started/src/Program.cs

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ namespace DocumentDB.GetStarted
2020
using Microsoft.Azure.Documents;
2121
using Microsoft.Azure.Documents.Client;
2222
using Microsoft.Azure.Documents.Linq;
23-
24-
// Add Newtonsoft.Json references
2523
using Newtonsoft.Json;
2624

2725
/// <summary>
@@ -61,44 +59,47 @@ public static void Main(string[] args)
6159

6260
private static async Task GetStartedDemo()
6361
{
64-
// Make sure to call client.Dispose() once you've finished all DocumentDB interactions
6562
// Create a new instance of the DocumentClient
6663
var client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey);
6764

6865
// Check to verify a database with the id=FamilyRegistry does not exist
6966
Database database = client.CreateDatabaseQuery().Where(db => db.Id == "FamilyRegistry").AsEnumerable().FirstOrDefault();
7067

68+
// If the database does not exist, create a new database
7169
if (database == null)
7270
{
73-
// Create a database
7471
database = await client.CreateDatabaseAsync(
7572
new Database
7673
{
7774
Id = "FamilyRegistry"
7875
});
76+
77+
WriteMessage("Created dbs/FamilyRegistry");
7978
}
80-
else { Warn("database"); }
8179

8280
// Check to verify a document collection with the id=FamilyCollection does not exist
83-
DocumentCollection documentCollection = client.CreateDocumentCollectionQuery(database.CollectionsLink).Where(c => c.Id == "FamilyCollection").AsEnumerable().FirstOrDefault();
81+
DocumentCollection documentCollection = client.CreateDocumentCollectionQuery("dbs/" + database.Id).Where(c => c.Id == "FamilyCollection").AsEnumerable().FirstOrDefault();
8482

83+
// If the document collection does not exist, create a new collection
8584
if (documentCollection == null)
8685
{
87-
// Create a document collection using the lowest performance tier available (currently, S1)
88-
documentCollection = await client.CreateDocumentCollectionAsync(database.CollectionsLink,
89-
new DocumentCollection { Id = "FamilyCollection" },
90-
new RequestOptions { OfferType = "S1" });
86+
documentCollection = await client.CreateDocumentCollectionAsync("dbs/" + database.Id,
87+
new DocumentCollection
88+
{
89+
Id = "FamilyCollection"
90+
});
91+
92+
WriteMessage("Created dbs/FamilyRegistry/colls/FamilyCollection");
9193
}
92-
93-
else { Warn("document collection"); }
9494

9595
// Check to verify a document with the id=AndersenFamily does not exist
96-
Document document = client.CreateDocumentQuery(documentCollection.DocumentsLink).Where(d => d.Id == "AndersenFamily").AsEnumerable().FirstOrDefault();
96+
Document document = client.CreateDocumentQuery("dbs/" + database.Id + "/colls/" + documentCollection.Id).Where(d => d.Id == "AndersenFamily").AsEnumerable().FirstOrDefault();
9797

98+
// If the document does not exist, create a new document
9899
if (document == null)
99100
{
100101
// Create the Andersen Family document
101-
Family AndersonFamily = new Family
102+
Family andersonFamily = new Family
102103
{
103104
Id = "AndersenFamily",
104105
LastName = "Andersen",
@@ -121,17 +122,18 @@ private static async Task GetStartedDemo()
121122
IsRegistered = true
122123
};
123124

124-
await client.CreateDocumentAsync(documentCollection.DocumentsLink, AndersonFamily);
125+
await client.CreateDocumentAsync("dbs/" + database.Id + "/colls/" + documentCollection.Id, andersonFamily);
126+
127+
WriteMessage("Created dbs/FamilyRegistry/colls/FamilyCollection/docs/AndersenFamily");
125128
}
126-
else { Warn("document"); }
127129

128130
// Check to verify a document with the id=AndersenFamily does not exist
129-
document = client.CreateDocumentQuery(documentCollection.DocumentsLink).Where(d => d.Id == "WakefieldFamily").AsEnumerable().FirstOrDefault();
131+
document = client.CreateDocumentQuery("dbs/" + database.Id + "/colls/" + documentCollection.Id).Where(d => d.Id == "WakefieldFamily").AsEnumerable().FirstOrDefault();
130132

131133
if (document == null)
132134
{
133135
// Create the WakeField document
134-
Family WakefieldFamily = new Family
136+
Family wakefieldFamily = new Family
135137
{
136138
Id = "WakefieldFamily",
137139
Parents = new Parent[] {
@@ -160,13 +162,13 @@ private static async Task GetStartedDemo()
160162
IsRegistered = false
161163
};
162164

163-
await client.CreateDocumentAsync(documentCollection.DocumentsLink, WakefieldFamily);
164-
}
165-
else { Warn("document"); }
165+
await client.CreateDocumentAsync("dbs/" + database.Id + "/colls/" + documentCollection.Id, wakefieldFamily);
166166

167+
WriteMessage("Created dbs/FamilyRegistry/colls/FamilyCollection/docs/WakefieldFamily");
168+
}
167169

168170
// Query the documents using DocumentDB SQL for the Andersen family
169-
var families = client.CreateDocumentQuery(documentCollection.DocumentsLink,
171+
var families = client.CreateDocumentQuery("dbs/" + database.Id + "/colls/" + documentCollection.Id,
170172
"SELECT * " +
171173
"FROM Families f " +
172174
"WHERE f.id = \"AndersenFamily\"");
@@ -178,17 +180,17 @@ private static async Task GetStartedDemo()
178180

179181
// Query the documents using LINQ for the Andersen family
180182
families =
181-
from f in client.CreateDocumentQuery(documentCollection.DocumentsLink)
183+
from f in client.CreateDocumentQuery("dbs/" + database.Id + "/colls/" + documentCollection.Id)
182184
where f.Id == "AndersenFamily"
183185
select f;
184186

185187
foreach (var family in families)
186188
{
187-
Console.WriteLine("\tRead {0} from LINQ", family);
189+
Console.WriteLine("Read {0} from LINQ", family);
188190
}
189191

190192
// Query the documents using LINQ lambdas for the Andersen family
191-
families = client.CreateDocumentQuery(documentCollection.DocumentsLink)
193+
families = client.CreateDocumentQuery("dbs/" + database.Id + "/colls/" + documentCollection.Id)
192194
.Where(f => f.Id == "AndersenFamily")
193195
.Select(f => f);
194196

@@ -197,40 +199,15 @@ from f in client.CreateDocumentQuery(documentCollection.DocumentsLink)
197199
Console.WriteLine("\tRead {0} from LINQ query", family);
198200
}
199201

200-
// Query the documents using DocumentSQl with one join
201-
var items = client.CreateDocumentQuery<dynamic>(documentCollection.DocumentsLink,
202-
"SELECT f.id, c.FirstName AS child " +
203-
"FROM Families f " +
204-
"JOIN c IN f.Children");
205-
206-
foreach (var item in items.ToList())
207-
{
208-
Console.WriteLine(item);
209-
}
210-
211-
// Query the documents using LINQ with one join
212-
items = client.CreateDocumentQuery<Family>(documentCollection.DocumentsLink)
213-
.SelectMany(family => family.Children
214-
.Select(children => new
215-
{
216-
family = family.Id,
217-
child = children.FirstName
218-
}));
219-
220-
foreach (var item in items.ToList())
221-
{
222-
Console.WriteLine(item);
223-
}
224-
225202
// Clean up/delete the database and client
226-
await client.DeleteDatabaseAsync(database.SelfLink);
203+
await client.DeleteDatabaseAsync("dbs/" + database.Id);
227204
client.Dispose();
228205
}
229206

230-
private static void Warn(string resource)
207+
private static void WriteMessage(string msg)
231208
{
232-
Console.WriteLine("Warning: A " + resource + " with the same id already exists");
233-
Console.WriteLine("Continuing may modify the existing " + resource + ".\nPress any key to continue.");
209+
Console.WriteLine(msg);
210+
Console.WriteLine("Press any key to continue ...");
234211
Console.ReadKey();
235212
Console.Clear();
236213
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Azure.DocumentDB" version="1.0.0" targetFramework="net45" />
4-
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
5-
</packages>
3+
<package id="Microsoft.Azure.DocumentDB" version="1.4.1" targetFramework="net45" />
4+
<package id="Newtonsoft.Json" version="5.0.7" targetFramework="net45" />
5+
</packages>

0 commit comments

Comments
 (0)