Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini
Desktop.ini
/.vs/config/applicationhost.config
15 changes: 11 additions & 4 deletions src/DocumentDBRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ public static class DocumentDBRepository<T> where T : class
private static readonly string CollectionId = ConfigurationManager.AppSettings["collection"];
private static DocumentClient client;


public static async Task<T> GetItemAsync(string id)
{
try
{
Document document = await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, CollectionId, id));
Document document = await client.ReadDocumentAsync(
UriFactory.CreateDocumentUri(DatabaseId, CollectionId, id),
new RequestOptions { PartitionKey = new PartitionKey("personal") }
);
return (T)(dynamic)document;
}
catch (DocumentClientException e)
Expand All @@ -40,7 +44,7 @@ public static async Task<IEnumerable<T>> GetItemsAsync(Expression<Func<T, bool>>
{
IDocumentQuery<T> query = client.CreateDocumentQuery<T>(
UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId),
new FeedOptions { MaxItemCount = -1 })
new FeedOptions { MaxItemCount = -1, EnableCrossPartitionQuery = true })
.Where(predicate)
.AsDocumentQuery();

Expand All @@ -65,7 +69,10 @@ public static async Task<Document> UpdateItemAsync(string id, T item)

public static async Task DeleteItemAsync(string id)
{
await client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, CollectionId, id));
await client.DeleteDocumentAsync(
UriFactory.CreateDocumentUri(DatabaseId, CollectionId, id),
new RequestOptions { PartitionKey = new PartitionKey("personal") }
);
}

public static void Initialize()
Expand Down Expand Up @@ -107,7 +114,7 @@ private static async Task CreateCollectionIfNotExistsAsync()
await client.CreateDocumentCollectionAsync(
UriFactory.CreateDatabaseUri(DatabaseId),
new DocumentCollection { Id = CollectionId },
new RequestOptions { OfferThroughput = 1000 });
new RequestOptions { OfferThroughput = 400 });
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions src/Models/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public class Item
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }

[JsonProperty(PropertyName = "category")]
public string Category = "personal";

[JsonProperty(PropertyName = "name")]
public string Name { get; set; }

Expand Down