Code Monkey home page Code Monkey logo

azure-cosmos-dotnet-v2's Introduction

🚨Deprecated 🚨

We've recently announced the deprecation of the Azure Cosmos DB .NET SDK Version 2. Starting August 2024 Microsoft will no longer provide support for this SDK. Existing applications using this library will continue to work as-is. We strongly recommend upgrading to the latest version of the SDK. For details on how to migrate your existing applications, follow our migration guide.

Microsoft Azure Cosmos DB .NET SDK Version 2

This project provides a client tools or utilities in .NET that makes it easy to interact with Azure Cosmos DB. Azure cosmos DB is published with nuget name Microsoft.Azure.DocumentDB.

Useful links:

Disclaimer

The implementation in this project is intended for reference purpose only.

Minimum Requirements

.Net 4.5

Consuming the official Microsoft Azure Cosmos DB SDK

From Package Manager Console

  Install-Package Microsoft.Azure.DocumentDB  

SDK release notes

https://github.com/Azure/azure-documentdb-dotnet/blob/master/changelog.md

https://docs.microsoft.com/azure/cosmos-db/sql-api-sdk-dotnet

Performance tips

https://docs.microsoft.com/azure/cosmos-db/performance-tips

Diagnose and troubleshooting issues

https://docs.microsoft.com/azure/cosmos-db/troubleshoot-dot-net-sdk

Samples

https://docs.microsoft.com/azure/cosmos-db/sql-api-dotnet-samples is a good starting point.

Also great source of samples can be found at https://github.com/Azure/azure-documentdb-dotnet/tree/master/samples

azure-cosmos-dotnet-v2's People

Contributors

aliuy avatar andrewhoh avatar arramac avatar ausfeldt avatar chwarr avatar codemillmatt avatar dependabot[bot] avatar ealsur avatar eawagu avatar giventocode avatar hedidin avatar heyyjudes avatar j82w avatar jcocchi avatar kirankumarkolli avatar markjbrown avatar microsoft-github-policy-service[bot] avatar mimig1 avatar mingaliu avatar mkolt avatar rafats avatar rnagpal avatar rsarosh avatar ryancrawcour avatar sakash279 avatar serkanpektas avatar snehagunda avatar sourabh1007 avatar stefarroyo avatar sychevigor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-cosmos-dotnet-v2's Issues

DeleteDocumentAsync throws NullReferenceException

Hello,

If I try to delete a nonexisting item like below

public static Document DeleteItem(Guid Id)
        {
                Uri uri = UriFactory.CreateDocumentUri(DatabaseId, CollectionId, Id.ToString());
                return client.DeleteDocumentAsync(uri).Result;
            }

I get a NullReferenceException. but the documentation here https://msdn.microsoft.com/en-us/library/microsoft.azure.documents.client.documentclient.deletedocumentasync.aspx states that I should have received DocumentClientException. am I missing something?

1.2 SDK? there is no 1.2 SDK

trying to use these samples but they won't build because they are referencing a NuGet package that is not available. come on. what's the point of publishing samples that do not work.

Geospatial query returns null due to localization issue

The issue is that my computer is in spanish therefore my decimal separator is a comma not a dot (like the server expects) so when I create a geospatial linq query against my collection it wont return result and no error. For example, it will send the position [ 9,9 , 88,8 ] which wont work because for it to be correct should be [ 9.9 , 88.8 ].

For example
where f.Location.Distance(new Point(lon, lat)) < distance
select f).ToList();

I had to build the query on my own simply by taking the lat and lon toString, which showed up the issue I assume the SDK is having, I corrected it on my own implementation and voila

Not able to implement in Azure Mobile App project

I have a fresh Azure Mobile App I created on the Azure portal and I am trying to implement DocumentDB on the backend. I used this repo as a basis for implementing the DomainManager and DocumentController. I have several issues with the Microsoft.WindowsAzure.Mobile.Service namespace in my VS2015 project.

I changed Microsoft.WindowsAzure.Mobile.Service.Tables to Microsoft.Azure.Mobile.Server.Tables and removed the references to Microsoft.WindowsAzure.Mobile.Service. This cleared up most of the reference issues. But, In the DomainManager and DocumentController I still have ApiServices references not found as well as LogCategories.

I am just learning DocumentDB and am looking to be pointed in the right direction with these issues. Any suggestions would be helpful.

Read/Replace/Delete From Partition Using UriFactory Link

My database implements a HashPartitionResolver similar to the example shown in the sample code.

This sample shows how to replace using database.selfLink, however, what if I want to use UriFactory with the database Id and document Id?

If I try something like this, I get "unexpected ResourceType" errors:

await client.ReplaceDocumentAsync("/dbs/my_database/docs/my_document", myDocument);

I see no option to provide a partition key parameter anywhere like CreateDocumentQuery<T> has.

How do I replace a document while using a partitioning strategy with ID based links? I also see the same issue with the Delete and Read methods.

Issue when using order by

Some queries return blank pages when using order by
For instance the query

select * from c where c.CustomerAreaId=”1” order by c.DocumentId

returns blank pages and a very high request charge. The response will indicate there is more data and if you keep getting the next page the data eventually starts to come back although due to the high request charge this is impractical.

However, if the queryis sorted desc then the data comes back immediately

select * from c where c.CustomerAreaId=”1” order by c.DocumentId desc

Index exclude path

Hi all,
When i modify existing collection and add something ( doesn't matter what ) to exclude path for collection indexing policy, i am getting error when i try to get this collection via .net sdk. For example here my indexing policy :

{
  "indexingMode": "consistent",
  "automatic": true,
  "includedPaths": [
    {
      "path": "/*",
      "indexes": [
        {
          "kind": "Range",
          "dataType": "Number",
          "precision": -1
        },
        {
          "kind": "Hash",
          "dataType": "String",
          "precision": 3
        }
      ]
    },
    {
      "path": "/\"_ts\"/?",
      "indexes": [
        {
          "kind": "Range",
          "dataType": "Number",
          "precision": -1
        },
        {
          "kind": "Hash",
          "dataType": "String",
          "precision": 3
        }
      ]
    }
  ],
  "excludedPaths": [
    {
      "path": "/name/?"
    }
  ]
}

And when i am trying to get this collection in my code

collection = client.CreateDocumentCollectionQuery(databaseSelfLink)
                                                  .Where(c => c.Id == collectionName)
                                                  .AsEnumerable()
                                                  .FirstOrDefault();

i am getting this error
message - Message: {"Errors":["One of the specified inputs is invalid"]}
ActivityId: f2334985-994e-4f19-a84f-4f12d278a9b4, Request URI: /apps/17417180-a55e-4a51-a53e-ed0cc8c1b21a/services/badf2bd0-ec51-4bfa-89ef-0977ad6528ba/partitions/ad670fbf-746c-4dd2-b642-cdd20cf34de1/replicas/130855494269012024p
stack trace -

   в Microsoft.Azure.Documents.Client.ClientExtensions.<ParseResponseAsync>d__4.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.Client.GatewayProxy.<>c__DisplayClass1f.<<InvokeAsync>b__1e>d__21.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.BackoffRetryUtility`1.<>c__DisplayClass2.<<ExecuteAsync>b__1>d__4.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteRetry>d__16.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteAsync>d__7.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.Client.GatewayProxy.<InvokeAsync>d__2c.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.Client.GatewayProxy.<ReadFeedAsync>d__1a.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.Client.DocumentClient.<ExecuteQueryAsync>d__2cb.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.Linq.DocumentQueryExecutionContext.<ExecuteOnceAsync>d__c.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.BackoffRetryUtility`1.<>c__DisplayClass2.<<ExecuteAsync>b__1>d__4.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteRetry>d__16.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteAsync>d__7.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.Linq.DocumentQueryExecutionContext.<ExecuteAllAsync>d__7.MoveNext()
--- The end of the stack trace from the previous location where the exception occurred ---
   в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   в System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   в Microsoft.Azure.Documents.Linq.DocumentQuery`1.<GetEnumeratorTAsync>d__10.MoveNext()

After i remove exclude paths - everything work as expected.
Client library - Microsoft.Azure.DocumentDB.1.4.0

How to deal with "Request size is too large" exceptions

I have a stored procedure which takes a parameter of a document array. I am getting into situations where I send too many documents at once and am getting a "Request size is too large" exception. I could easily avoid this by just calling the stored procedure multiple times with smaller sets of data until all is done. My question is, using the SDK, how can I determine the size of the data I am about to send to the stored procedure before calling it? Ideally I want to send as many documents as possible in one call without going over this limit. I could just make this number something low and realistic, say 10, but what if these 10 documents are so large themselves that the exception will still occur. Some cases I could send 200 and be fine, while others I can only send 5.

Sync operations hang up when run under Orleans

I did a dotPeek into sources, and seems like sync operation (CreateDatabaseQuery, CreateDocumentCollectionQuery etc) are actually async, but with some kind of dispatching overrides, aren't they?

Unfortunatily this behavior is pretty bad for environements, that are in control of task dispatching like Orleans: http://dotnet.github.io/orleans/Advanced-Concepts/External-Tasks-and-Grains

as a workaround I wrap SDK with something like:

public async Task<DocumentCollection> GetCollection(Database db, string collectionId) {
                return await Task.Run(
                                () => client.CreateDocumentCollectionQuery(db.SelfLink)
                                    .Where(c => c.Id == collectionId)
                                    .AsEnumerable()
                                    .FirstOrDefault()
                            );
}

very long ResponseContinuation on certain query

If I run this query
SELECT * FROM c WHERE c.ObjectType="Document"
I get a
ResponseContinuation = "+RID:16gQALRRBgM-AAAAAAAAAA==#RT:1"

if I run the following query (on the same collection)
SELECT * FROM c WHERE c.CustomerAreaId = "1"
the ResponseContinuation is 7755 bytes long

ResponseContinuation = "+RID:16gQALRRBgPrggsAAAAAAA==#RT:1#FPC:AgEuPC6KBu8CAPDd9/3e9/f9//f3+3v1/v7/+//v9/e/f3//fn+rRsDf7//ff/W9///96Pt9b/u+f3///v/f7//7+//3/t/vv3///v/+//3v3/v+///Bfb/f37+///++/77fu7uv3e+3vW/+//+/v+2+//vf//7/t/b97/9v2/v+9/v79/f7/f7v7zvt/f37/d9/v/v9ff+/3+v+/vf3//f7/...

Is this ResponseContinuation correct or should it just look like that in the first example.
If I edit it to remove everything after the #RT:1 it appears to work but it is very difficult to be sure with the amount of data in the collection. If the ResponseContinuation is correct I will have to re-engineer my paging mechanism in my web site as this is far too much data to transfer

SelectMany doesn't work after Select

I have such query:

.Select(x => x.Document).SelectMany(x => x.Members.Select(m => new { TripId = x.TripId, UserId = m.UserId }))

And it's translated to such SQL:
SELECT VALUE {TripId: root["Document"]["TripId"], UserId: m["UserId"]} FROM root JOIN m IN root["Members"] WHERE STARTSWITH(root["id"], "TripMembers") which is incorrect - this part is inccorrect: root["Members"]

When I use that query:

.SelectMany(x => x.Document.Members.Select(m => new { TripId = x.Document.TripId, UserId = m.UserId }))

then it's translated to correct SQL:

SELECT VALUE {TripId: root["Document"]["TripId"], UserId: m["UserId"]} FROM root JOIN m IN root["Document"]["Members"] WHERE STARTSWITH(root["id"], "TripMembers")

Add support for DNX Core

Please add a DNX Core version of Microsoft.Azure.DocumentDB. (If you add the code here, I'll help do the work!)

Resource not found errors

I have an application that has been working reliably for some time. As of around 4.30 pm (UK time) on 24/11/2015 it started to exhibit resource not found errors.
Basically the application has a collection called "System" where it stores system settings. It executes regularly against that collection to retrieve settings. Most of those settings retrieve fine but a couple suddenly started to receive frequent (but not always!) resource not found errors.
I copied the entire contents of that collection to a new collection called "System2" and reconfigured the application to read from that collection instead and the errors no longer occur.
It leave me to believe there is an issue with one of the replicas or could there be something I am not doing correctly in my application?
I can grant access if you would like to look, otherwise I will delete and rebuild the "System" collection.

Error saving ID field containing a forward slash '/' [.NET SDK 1.2.0]

Currently with version 1.2.0 it is not possible to create documents that contain a forward slash in the ID field.

In my case I am using the sample DocumentDBRepository class for convenience and passing in the following:

await DocumentDBRepository<Supplier>.CreateItemAsync(new ExampleModel{Id = "test/document"}); 

ExampleModel:

public class ExampleModel
{
    [JsonProperty(PropertyName = "id")]
    public String    Id    { get; set; }
}

In my code I am not catching the error but when I try to edit a document using Azure Document DocumentDB Studio with an ID of "document" to name it "test/document" I get the following:

 System.ArgumentException: The resource name presented contains invalid character '/'.
    at Microsoft.Azure.Documents.Client.DocumentClient.ValidateResource(Resource resource)
    at           Microsoft.Azure.Documents.Client.DocumentClient.<ReplaceDocumentPrivateAsync>d__f2.MoveNext     ()
 --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification     (Task task)
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
    at Microsoft.Azure.DocumentDBStudio.DocumentNode.<UpdateNode>d__58.MoveNext() in      f:\git\DocumentDB-studio\DocumentDBStudio\TreeNodes.cs:line 1345

Interestingly I am able to edit the document to give it the desired ID when I edit through the Document Explorer within the Azure Portal.

Edit: Just want to add that I have reverted back to version 1.1.0 of the .NET SDK which does not have this particular issue.

DocumentClient.ReadDocumentAsync should not query across collections/databases

I inadvertently constructed an inconsistent documentLink - the resource ID existed, but not in the db/coll that I specified - and was surprised to see that DocumentClient.ReadDocumentAsync happily returned the resource nonetheless.

The same goes for DocumentClient.ReplaceDocumentAsync, it also happily accepted my inconsistent documentSelfLink.

I'm using the .NET SDK NuGet package.

<package id="Microsoft.Azure.Documents.Client" version="0.9.2-preview" targetFramework="net45" />
or
<package id="Microsoft.Azure.DocumentDB" version="1.1.0" targetFramework="net45" />

Here's the setup I used:

  • One DocumentDB account
  • Two databases within that account
  • Identical schemas for the two databases: same DocumentCollection.Ids, same types of documents within those collections. (Different ResourceIds for the DocumentCollections and the documents though, of course.)

Here's some code that reproduces the problem.

var endpointUrl = "https://gfms-dev.documents.azure.com:443/";
var authorizationKey = "secret";
var client = new DocumentClient(new Uri(endpointUrl), authorizationKey);

var databaseId = "GFMS-oscar";
var database = client.CreateDatabaseQuery().Where(x => x.Id == databaseId).AsEnumerable().Single();

var collectionId = "Interview";
var collection = client
    .CreateDocumentCollectionQuery(database.CollectionsLink)
    .Where(c => c.Id == collectionId)
    .AsEnumerable()
    .Single();

// A document with this resource ID exists on this account, but in a different database and collection than the ones above.
var resourceId = "RUBKAOVM1AIDAAAAAAAAAA==";
// The collection.DocumentsLink doesn't even matter, "dbs/foo/colls/bar/docs/" + resourceId works just as well.
var documentLink = collection.DocumentsLink + resourceId;
// This should fail, but it succeeds.
var response = await client.ReadDocumentAsync(documentLink);
var document = response.Resource;

// Fails: the doc-id is the same, but the db-id and col-id are not.
Assert.AreEqual(documentLink, document.SelfLink);

I had expected the request to fail with an exception, either because the documentLink is inconsistent, or because the specified resource ID does not exist in the specified collection.

I can see a use for an API that finds documents regardless of which db/collection they reside in. However, then I don't see the point of having to specify a full document self link, including database ID and collection ID. In that case, just the resource ID should be sufficient.

Unable to Serialize Subclasses of "Document"

Problem

I have a class that I want to store in Document DB. I subclassed this from Document because my Repository/Data Access layer cares about such things.

To be clear - it's something like:

public class MyDocument : Document {
    public string Custom { get; set; }
}

// After creating a document, I want to be able to do things like:
var doc = new MyDocument { Custom = "Something" };
var id = doc.Id;
var link = doc.SelfLink;
var custom = doc.Custom;

Within the code - all this appeared to be working fine, but when it came to serialization, my Custom property was being dropped.

I started to dig around and found that Document is a subclass of JsonSerializable - where there seems to be something amiss.

So - I got the code out to isolate it - the instance created from FromObject looks OK (you can see the Custom property) - but when serialized, the information is lost.
NOTE: We know this isn't a problem with JSON.NET - that handles subclasses fine.

Observe - I created the following in LINQpad (just add references to Azure.Documents.Client and Newtonsoft.Json and copy/paste):

void Main()
{
    var testDoc = new MyDocument {
        Custom = "Some Custom Property"
    };

    var test = FromObject(testDoc);
    test.Dump("Object Created from Document.FromObject - 'Custom' property visible:");
    JObject.FromObject(test).ToString().Dump("Serialized object - Y U NO SAVE?");
}

public class MyDocument : Document {
    public string Custom { get; set; }
}

internal static Document FromObject(object document) {
    if (document == null)
        return (Document) null;

    if (typeof (Document).IsAssignableFrom(document.GetType()))
        return (Document) document;

    JObject jobject = JObject.FromObject(document);
    Document document1 = new Document();
    // Private fields be damned!
    typeof(Document).GetField("propertyBag").SetValue(document1, jobject);
    // document1.propertyBag = jobject;
    return document1;
}

SUGGEST: I was really surprised to see this happening. Get Document to a POCO so we can subclass freely. It's serialization should be handled elsewhere.

PS: I'm not blocked - I can work around this.

Add a generic overload to ReadDocumentAsync

Currently, CreateDocumentQuery allows the results to be returned in a strongly typed manner using generics. Why doesn't ReadDocumentAsync have a similar overload? There should be a simple method to load a document of a known type without resorting to casting and dynamics.

This is especially important now that self links have been de-emphasized and we have the new UriFactory.

What I'm envisioning is:

var uri = UriFactory.CreateDocumentUri("DB", "Collection", "id");
var myDocument = await client.ReadDocumentAsync<MyDocument>(uri);

Alternatively, perhaps this should belong in a different method such as GetDocument<T>(Uri link)

Collection quota not consistent

When using the SDK to retrieve the document quota the results I get are inconsistent. The collections are currently static so the values should not be changing. The result is most noticeable when the queries are performed by my published web site rather than local host.

Here is a table showing a collection and the two sets of results I get. When run a number of times the values alternate randomly between the two sets of values.

Collection Mode % Storage Used Performance Level

User2 Consistent 11.67 S1

User2 Consistent 14.48 S1

If we compare with the value shown on the portal, the portal shows 1.45 GB used (14.48%) which agrees with only one set of results. I have not seen the portal show different values.
I currently only have one collection in the database that has anywhere near this amount of data so I cannot see it being a programming error and it is not restricted to this particular collection.

I am assuming that the information is coming from different replicas but why should there be such a large difference (if you expect there to be any difference at all!).

I am currently using Gateway mode.

Issue with StartsWith query

Following is a table of results for some queries from the same collection using the portal although I get the same results using my own application with the sdk (1.4.1)

select * from c where c.ObjectType="System.SearchIndexQueueItem" 29.27 RUs 100+ results
select * from c where c.ObjectType="Document" 37.39 RUs 100+ results

select * from c where StartsWith(c.ObjectType,"Doc") 42.42 RUs 100+ results
select * from c where StartsWith(c.ObjectType,"Sys") 1035 RUs shows no results but Has More Results is True

So the last query should return results but does not. I have seen a report elsewhere that someone is having the converse issue (the StartWith works but the equality (=) does not) so there is clearly an issue here.
I can provide further information/screenshots etc if necessary on request). I have attached some screenshots below

equality
startswith
startswithdoc

Incorrect SQL query generated from linq expression

Hi,

I've been studying console app example, and I tried to select all families which have children that are in fifth grade.

So here is my linq query:

var list = client.CreateDocumentQuery<Family>(documentCollection.DocumentsLink)
             .SelectMany(family => family.Children
             .Where(x => x.Grade == 5)
             .Select(child => new
             {
                 family = family.Id,
                 child = child.FirstName
             })).ToList();

But resultset contains only 'family' values whereas 'child' is null.
I'd checked generated SQL query and got this:

SELECT VALUE {family: root.id, child: root.FirstName} FROM root JOIN x IN root.Children WHERE (x.Grade = 5) 

so FirstName value takes from 'root' (Family), not from 'x'

Is it an issue in query builder or i'm just building expression in a wrong way?

Query ignoring feed options?

I am not sure if this actually an issue but it is not doing what i expected (hoped).
I use the following code to get the first document based on a query. I have just imported 1.5 million documents into my system and I find that if I execute this using a query that matches a lot of documents the query looks like it is returning all the documents before returning the FirstOrDefault (because the query is essentially hanging).

var document = client.CreateDocumentQuery(documentsLink, query, MaxOneDocument).AsEnumerable().FirstOrDefault();

private FeedOptions MaxOneDocument {
get { return new FeedOptions() { MaxItemCount = 1 }; }
}

I have an alternative which does work (using .AsDocumentQuery()) so I can change to using that instead but I am interested to know if the above is the correct intended behaviour.

ReliableReadDocumentClient throws "Request rate is large" exception from CreateDocumentCollectionQuery method

I see that ReliableReadDocumentClient implemented in Microsoft.Azure.Documents.Client.TransientFaultHandling, Version=1.2.0.0 throws "Request rate is large" exception from method CreateDocumentCollectionQuery, but as I believe it shouldn't.

See code snippet below:

    static void Main(string[] args)
    {
        var ts = new List<Thread>();
        for (int j = 0; j < 100; ++j)
        {
            var t = new Thread(() =>
            {
                try
                {
                    using (var client = CreateReliableClient())
                    {
                        Database database = client.CreateDatabaseQuery().Where(db => db.Id == DatabaseId).ToArray().FirstOrDefault();
                        // the next line throws exception 
                        DocumentCollection collection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == CollectionId).ToArray().FirstOrDefault();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.InnerException.Message);
                }
            });
            t.Start();
            ts.Add(t);
        }

        foreach (var t in ts)
        {
            t.Join();
        }
    }

    static IReliableReadWriteDocumentClient CreateReliableClient()
    {
        return new DocumentClient(new Uri(EndpointUrl), AuthorizationKey)
            .AsReliable(new FixedInterval(10, TimeSpan.FromSeconds(1)));
    }

Could you please fix it?

LINQ Query Does Not Respect JsonProperty Attribute

Using LINQ in the SDK does not produce the correct query. See the following example:

My User class:

public class User
{
    [JsonProperty("id")]
    public string Id { get; private set; }
    [JsonProperty("type")]
    public string Type { get; private set; }

    public string Username { get; set; }

    // ....
}

and LINQ query:

Client.CreateDocumentQuery<User>(DatabaseUri, new FeedOptions { MaxItemCount = 1 })
    .Where(d => d.Id == "GUID").AsEnumerable();

produces the following query:

SELECT * FROM root WHERE (root.Id = "GUID")

This finds no results because Id was not lowercase in the query, as specified in the JsonProperty attribute.

Running this query in the portal with the query explorer manually returns the expected result:

SELECT * FROM root WHERE (root.id = "GUID")

LINQ generate wrong query for join

I have LINQ that generate wrong query to DocumentDb:

var query = client.CreateDocumentQuery(colSelfLink)
.SelectMany(doc => doc.SomeProperty.Items.Where(item => item == "002").Select(_ => doc));

Expected query:
SELECT VALUE root FROM root JOIN item IN root.SomeProperty.Items WHERE (item = "002")

Actual query:
SELECT VALUE root FROM root JOIN item IN root.Items.SomeProperty WHERE (item = "002")

Model:
public class Model
{
public string id { get; set; }
public SomePropertyModel SomeProperty { get; set; }

public class SomePropertyModel
{
    public string[] Items { get; set; }
}

}

Microsoft.Azure.Documents.Client version:
"0.9.0.0"

Add ODM like mongoosejs

I'd like to propose an Object Document Mapper library added to the dotnet sdk, with functionality similar to the mongoose library for mongo/node ( http://mongoosejs.com/ ) or the morphia library for mongo/java ( https://github.com/mongodb/morphia )

Core functionality of a DDB ODM should include:

  1. Simplified connection methods
  2. Annotation definitions for POCO's
  3. CRUD operations (w/ LINQ support)

It would also be nice to have:

  1. External relationship mapping between objects
  2. Plugin framework

PCL

Any plans to make the DocumentDB Client Library available as a portable class library?

DocumentClient.ValidateResource invalid character

I create my document IDs using a hash that I translate into a string with the returned bytes. A particular hash returned the "?" character.

The method DocumentClient.ValidateResource threw an exception stating "The resource name presented contains invalid character '?'."

Issue #35 states this is due to the ID having an invalid URI character.

I looked up the list of reserved characters for URIs. RFC 3986 https://tools.ietf.org/html/rfc3986

To resolve this I sought to use HttpUtility.UrlEncode or Uri.EscapeUriString. However, both of those methods exclude "!()*" (These stack overflow questions state this as well, with no resolution.)
http://stackoverflow.com/questions/30932903/net-urlencode-not-working
http://stackoverflow.com/questions/575440/url-encoding-using-c-sharp/21771206#21771206

Interestingly creating a document with an ID using any of these 4 characters "!()*" is created without issue, even though they are technically reserved characters for the URI Syntax.

Since the code is not yet posted: Can you tell me what methods the ValidateResource is using against the ID Field?

Will this change one day to include these 4 characters? It would be nice to use the library methods instead of having to keep an eye out for these 4 characters.

Thanks.

Linq to DocumentDb, where clause on child

In a project i'm currently working on, we have come to realise that we should not use DocumentDb collections as if they are the equivalent of a table in f.ex SQL Server. As a result, we are now persisting all of the entities, belonging to a single tenant in a single collection.

We already have lots of linq queries in our codebase which assume that each document type (aggregate root) is persisted in a dedicated collection. In an attempt to make the transition painless, i set out to refactor our data access object, so that its api continues to reason about aggregate roots, and deal with the single collection vs dedicated collections in it's implementation.

My approach is to wrap an aggregate root in an Resource<T> object, which derives from Resource and exposes a Model property as well as a Type property. I thought i would then be able to expose an IQueryable<T> to consuming code based on the following code:

        return _client.CreateDocumentQuery<Resource<TModel>>(_collection.DocumentsLink)
            .Where(x => x.Type == typeof(TModel).Name)
            .Select(x => x.Model);

Initial testing showed that this worked as planned and i confidently committed my changes. When doing functional testing however, we found that some queried models had all of their properties set to their default values (ie. null, 0, false, etc).

I can reproduce the problem with the following code:

        var wrong = _client.CreateDocumentQuery<Resource<TModel>>(_collection.DocumentsLink)
            .Where(x => x.Type == typeof(TModel).Name)
            .Select(x => x.Model)
            .Where(x => !x.IsDeleted)
            .ToArray();

        var correct = _client.CreateDocumentQuery<Resource<TModel>>(_collection.DocumentsLink)
            .Where(x => x.Type == typeof(TModel).Name)
            .Where(x => !x.Model.IsDeleted)
            .Select(x => x.Model)
            .ToArray();

The results of the above queries are not the same!!

  • Both queries return the same number of TModel instances.
  • Only the instances returned by the second example have their properties populated.

In order for my refactoring to be successful, i need wrong to be ... right :) Falling back to SQL is not an option as we value type safety of linq. Changing our approach to expose the Resource<T> objects would touch lots of code, as it requires all *.Property references to be substituted by *.Model.Property references.

It seems an issue with the linq provider that is part of the DocumentDb client.

We use Microsoft.Azure.DocumentDb version 1.4.1

Retries Failing with RequestRateTooLargeException

I am calling ReplaceDocumentAsync and getting RequestRateTooLargeExceptions. From what I read, the SDK should be retrying requests for me automatically. My guess is that I am getting this exception still because it retried too many times and still failed? Is this the case? If so, is this configurable?

  at Microsoft.Azure.Documents.RntbdTransportClient.ThrowIfFailed(String resourceAddress, StoreResponse storeResponse, Uri physicalAddress, Guid activityId)
   at Microsoft.Azure.Documents.RntbdTransportClient.<InvokeStoreAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Azure.Documents.ReplicatedResourceClient.<WriteAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Azure.Documents.ReplicatedResourceClient.<InvokeAsync>d__b.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Azure.Documents.ReplicatedResourceClient.<>c__DisplayClass1.<<InvokeAsync>b__0>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Azure.Documents.BackoffRetryUtility`1.<>c__DisplayClassd`1.<<ExecuteAsync>b__c>d__f.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteRetry>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Azure.Documents.BackoffRetryUtility`1.<ExecuteAsync>d__12`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Azure.Documents.ReplicatedResourceClient.<InvokeAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Azure.Documents.StoreClient.<ProcessMessageAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Azure.Documents.Client.DocumentClient.<UpdateAsync>d__2a9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Azure.Documents.Client.DocumentClient.<ReplaceDocumentPrivateAsync>d__f3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.Azure.Documents.Client.DocumentClient.<ReplaceDocumentPrivateAsync>d__eb.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Core.Repositories.DocumentDB.Repository`1.<ReplaceAsync>d__3.MoveNext() in C:\\*********\\Repository.cs:line 33
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Core.Services.UserService.<ChangePasswordAsync>d__17.MoveNext() in C:\\*********\\UserService.cs:line 202
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Api.Controllers.AccountsController.<PutPassword>d__10.MoveNext() in C:\\*********\\AccountsController.cs:line 120
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNet.Mvc.Controllers.ControllerActionExecutor.<CastToObject>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker.<InvokeActionAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeActionFilterAsync>d__53.MoveNext()

DocumentDb upsert: which TriggerOperations apply?

When registering triggers, and using the new upsert functionality for create/update, which TriggerOperation applies to this situation?

Thanks,
Kirk


//
// Summary:
//     Specifies the operations on which a trigger should be executed.
public enum TriggerOperation : short
{
    //
    // Summary:
    //     Specifies all operations.
    All,
    //
    // Summary:
    //     Specifies create operations only.
    Create,
    //
    // Summary:
    //     Specifies update operations only.
    Update,
    //
    // Summary:
    //     Specifies delete operations only.
    Delete,
    //
    // Summary:
    //     Specifies replace operations only.
    Replace
}

Posible bug in select statement

When I run this select I get 0 results: SELECT ST_DISTANCE(l.Geometry, { "type": "Point", "coordinates": [1,1]}) AS dist FROM l WHERE l.dist > 1

But if I change the query to look like this: SELECT ST_DISTANCE(l.Geometry, { "type": "Point", "coordinates": [1,1]}) AS dist FROM l WHERE ST_DISTANCE(l.Geometry, { "type": "Point", "coordinates": [1,1]}) > 1
I get the expected result.

CreateDocumentCollectionQuery phantom exception

Hi, when i am executing this code on the server :

 public async Task<List<DocumentCollection>> GetAllCollections()
        {
            var uri = UriFactory.CreateDatabaseUri(Database.Id);
            var query = Client.CreateDocumentCollectionQuery(uri)
                             .AsDocumentQuery();

            List<DocumentCollection> fetchedCollections = new List<DocumentCollection>();

            do
            {
                try
                {
                    var result = await query.ExecuteNextRetryAsync<DocumentCollection>();
                    fetchedCollections.AddRange(result.Where(x => x.Id != MasterCollection.Id));
                }
                catch (Exception err)
                {
                    throw new Exception(" DATABASE ID = " + Database.Id + Environment.NewLine + " ORIGINAL = " + err.Message + Environment.NewLine + " QUERY = " + query.ToString() );
                }

            } while (query.HasMoreResults);

            return fetchedCollections;
        }

In 75% of cases it throws next exception

System.Exception:  DATABASE ID = jobtapdb-dev-release 
ORIGINAL = Message: {"Errors":["Resource Not Found"]}
ActivityId: e19d59ba-d975-40bf-be8f-8b1e5688133f, 
Request URI: /apps/17417180-a55e-4a51-a53e-ed0cc8c1b21a/services/badf2bd0-ec51-4bfa-89ef-0977ad6528ba/partitions/ad670fbf-746c-4dd2-b642-cdd20cf34de1/replicas/130881235279192159s
QUERY = https://jobtapdb-dev-release.documents.azure.com/dbs/jobtapdb-dev-release  
 at Boomerang.Infrastructure.DocumentDbRepository.CollectionRepository.<GetAllCollections>d__2.MoveNext() in c:\Work\Git\boomerang-api-azure_2\Boomerang\Boomerang.Infrastructure\DocumentDbRepository\CollectionRepository.cs:line 49--- End of stack trace from previous location where exception was thrown ---   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()   at Boomerang.ServiceInterface.Services.CompanyCreateService.<Post>d__12.MoveNext()

Any suggestions ?
Thanks

Int64 serialization culture problem

When using the SDK to query (with Linq) for a document I ran into some problems with filtering a query on a Int64 property.

I figured out that in the REST request the Int64 is serialized as (for example) 6,35430269777489E+17 which results in a server error. It seems that this is because of my local machines culture settings (nl-NL).

I've created an example application to show the bug, or am I missing something?
https://github.com/keesschollaart81/DocumentDbSerializationTest

Many source code links are broken

For instance on page DocumentDB Partitioning Samples all links like this:

https://github.com/Azure/azure-documentdb-net/tree/master/samples/partitioning/DocumentDB.Samples.Sharding/DocumentDB.Samples.Sharding/Partitioners/LookupPartitionResolver.cs

should actually lead to:

https://github.com/Azure/azure-documentdb-net/blob/master/samples/code-samples/Partitioning/Partitioners/LookupPartitionResolver.cs

DocumentDb error "One of the specified inputs is invalid" when json serialization is TypeNameHandling.All

Hi all,
We're using v1.5.2 and getting the error "One of the specified inputs is invalid".

It occurs when calling CreateDocumentCollectionAsync and CreateDocumentQuery, and JsonSerializerSettings sets TypeNameHandling = TypeNameHandling.All.

An example of calling CreateDocumentQuery:

var sqlQuerySpec = new SqlQuerySpec();
sqlQuerySpec.QueryText = "SELECT * FROM c where c.UserName = @userName";
sqlQuerySpec.Parameters = new SqlParameterCollection();
sqlQuerySpec.Parameters.Add(new SqlParameter() { Name = "@userName", Value = "John Doe" });

var queryResult = _documentClient.CreateDocumentQuery(_collection.SelfLink, sqlQuerySpec).AsEnumerable();

Using sql expression with no parameters, it works ok.
Using lambda expression, it works ok.
Setting TypeNameHandling to default value, works ok too.

Warm greetings!

Is LINQ not using JsonConverter ?

In Partitioning project, in Program.RunCrudAndQuerySample, the UserProfile available iteration cannot work.

            query = this.client.CreateDocumentQuery<UserProfile>(database.SelfLink).Where(u => u.Status == UserStatus.Available);
            foreach (UserProfile activeUser in query)
            {
                Console.WriteLine(activeUser); // never executed
            }

The document created has a Status value "Available" when the query generated is using the int value (0).
I could fix it with the removing of the JsonConverter attribute, but I expected the LINQ query builder to use the JsonConverter attribute to keep an homogeneous behavior.

Support for Skip

Please add Linq support for Skip since it would make it much easier, and possible at all in many scenarios, to use paging.

Example on how I would do it with Linq To Sql: return query.Skip((pageNumber - 1) * pageSize).Take(pageSize);

This is sadly not possible after switching to DocumentDB. Therefore I, and many others, would love it if you implemented support for Skip

ArgumentOutOfRangeException when combineing Model projection with Where-In in linq query

A where in, or Array.Contains(..) linq query results in an ArgumentOutOfRangeException when a projection (as in Select(x => x.projection)) is used before the where clause.

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: Unexpected Sql Scalar expression kind InExpression

I expected it to not fail and translate the expression into a where in query to Azure Documents.

Test code:

using System;
using System.Linq;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class DocumentTests
{
    private DocumentClient _client;
    private Database _database;
    private DocumentCollection _documentCollection;

    [TestInitialize]
    public void Setup()
    {
        _client = new DocumentClient(new Uri("uri"),"secret");
        _database = _client.CreateDatabaseQuery().Where(db => db.Id == "DocumentTesting").AsEnumerable().FirstOrDefault();

        if (_database == null)
        {
            _database = _client.CreateDatabaseAsync(
                new Database
                {
                    Id = "DocumentTesting"
                }).Result;
        }

        _documentCollection = _client.CreateDocumentCollectionQuery("dbs/" + _database.Id)
            .Where(c => c.Id == "TestCollection").AsEnumerable()
            .FirstOrDefault();

        if (_documentCollection == null)
        {
            _documentCollection = _client.CreateDocumentCollectionAsync(
                "dbs/" + _database.Id,
                new DocumentCollection
                {
                    Id = "TestCollection"
                }).Result;
        }

        var document = _client.CreateDocumentQuery<TestResource>("dbs/" + _database.Id + "/colls/" + _documentCollection.Id)
            .Where(d => d.Name == "foo").AsEnumerable()
            .FirstOrDefault();

        if (document == null)
        {
            document = new TestResource { Name = "foo", Model = new TestModel { Name = "bar" } };

            _client.CreateDocumentAsync("dbs/" + _database.Id + "/colls/" + _documentCollection.Id, document).Wait();
        }
    }

    [TestMethod]
    public void WhereInQuery_WithoutProjection_WithStaticList()
    {
        var result = _client.CreateDocumentQuery<TestResource>(_documentCollection.DocumentsLink)
                .Where(res => new[] { "foo" }.Contains(res.Name))
                .AsEnumerable().ToArray();

        Assert.AreEqual("foo", result.First().Name);
    }

    [TestMethod]
    public void WhereInQuery_WithoutProjection_WithDynamicList()
    {
        var names = new[] { "foo" };
        var result =
            _client.CreateDocumentQuery<TestResource>(_documentCollection.DocumentsLink)
                .Where(res => names.Contains(res.Name))
                .AsEnumerable().ToArray();

        Assert.AreEqual("foo", result.First().Name);
    }

    [TestMethod]
    public void WhereInQuery_WithProjection_WithStaticList()
    {
        var result =
            _client.CreateDocumentQuery<TestResource>(_documentCollection.DocumentsLink)
                .Select(res => res.Model)
                .Where(res => new[] { "bar" }.Contains(res.Name))
                .AsEnumerable().ToArray();

        Assert.AreEqual("bar", result.First().Name);
    }

    [TestMethod]
    // !!! THIS ONE FAILS !!!
    public void WhereInQuery_WithProjection_WithDynamicList()
    {
        var names = new[] { "bar" };
        var result =
            _client.CreateDocumentQuery<TestResource>(_documentCollection.DocumentsLink)
                .Select(res => res.Model)
                .Where(res => names.Contains(res.Name))
                .AsEnumerable().ToArray();

        Assert.AreEqual("bar", result.First().Name);
    }

    private class TestResource : Resource
    {
        public string Name { get; set; }
        public TestModel Model { get; set; }
    }

    private class TestModel
    {
        public string Name { get; set; }
    }
}

Unable to import documents at the rate I should be able to

I am trying to import documents from an external source. The collection that is being used to import into has performance level S3 - therefore 2500 request units. The documents I am importing (which are in the main of very similar size - 1150 bytes) report a charge of 3.5 RU's on average when inserted.
Therefore I should be able to import at a rate of about 700 documents/sec.
The maximum rate I can seem to achieve is around 150 documents/sec.

I read in the documents to import from storage and when the document insert is commented out it flies so the issue appears to be with the insert into documentdb. The code uses threads heavily but no matter how many threads I create the rate will not exceed this amount.

I also have tried the bulk import stored procedure found on this site but that has no effect , the rate is still about the same.
Note that this is all running from within a deployed Azure application.

Any suggestions why this might be?
(I know there is a documentdb import tool available on github but it doesn't satisfy my specific requirements)

Different Partitioning Schemes in the same database

We are currently setting the number of partitions in a single DocumentDb database on a per entity-basis by overwriting the parititionresolver dictionary entry on a per-entity basis.

Although we've proved that we have different instances of the DocumentDbClient and therefor different ParititonResolver dictionaries it doesn't seem to work if the collection counts are different.

We are wondering if variable partition counts in a single database is supported ? Since the DocumentDbClient Dictionary for Partition Resolves is keyed by database should we be separating our entities with different partition requirements into separate databases ?

Cannot list a collection created through the portal

I created a new collection using the azure portal. When I try to list the available collections within my application I get the following error.

Errors":["The collection 'User1' could not be read because it was created with a newer API version.

According to NuGet I have the latest Microsoft.Azure.DocumentDB library installed (Version 1.1.0)

Changing Json.net serialization options

I've been googling around, and I know revealing this option to the user isn't currently supported by the library, and the workaround is to set this somewhere in the application:

JsonConvert.DefaultSettings = () =>
{
    return new JsonSerializerSettings
    {
        TypeNameHandling = TypeNameHandling.All
    };
};

However, this isn't working for me, and my application requires the use of TypeNameHandling to deal with abstract classes in Collections. Is there a currently known work around to do this? I'm using the latest package, and running on dnx451.

sdk directory is empty

Is this where the sources for Microsoft.Azure.Documents.Client nuget should reside?
The code in /sdk seems to be missing - there is only a readme.txt saying "source code for DocumentDB .NET SDK".
Is it possible to add the code here?

Order by asc and desc give different results

If I perform the following query
select c.id,c.TenantId,c.ObjectType from c where c.TenantId="James Industries PLC" order by c._ts asc

the query explorer returns a page of results with HasMoreResults = true

However, with the same query sorted desc
select c.id,c.TenantId,c.ObjectType from c where c.TenantId="James Industries PLC" order by c._ts desc

only 3 results were returned with the HasMoreResults flag set to false. There are 397343 objects that should match this query in the database. Screenshots to show this included.

The discrepancy varies. I have paged through all the results asc at times and found that the number of results falls short by about 100 compared to when no sort is performed but this varies and at times shows no discrepancy at all.

Since the collection I am experiencing this on is highly dynamic I have created a copy of the collection which I can keep for you to inspect. However, this collection gives different results. In this case the asc query returns no results and HasMoreResults=false wheres the desc search returns a page and HasMoreResults=true. Screenshots to show this also included. Note that this copy was made by inserting all the documents into a new collection with no indexing policy and then applying the indexing policy later.

I can give you access details for the databases on request.

Here are the screenshots (original)
org_orderbyasc
org_orderbydesc

copy
cpy_orderbyasc
cpy_orderbydesc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.