本文整理汇总了C#中Microsoft.Azure.Documents.Client.DocumentClient.CreateDocumentQuery方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentClient.CreateDocumentQuery方法的具体用法?C# DocumentClient.CreateDocumentQuery怎么用?C# DocumentClient.CreateDocumentQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Azure.Documents.Client.DocumentClient
的用法示例。
在下文中一共展示了DocumentClient.CreateDocumentQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main(string[] args)
{
var client = new DocumentClient(new Uri("https://url.com:443/"), "**********");
var database = GetDatabase(client);
var documentCollection = GetDocumentCollection(client, database);
Test(
"Via Linq lambda",
new[] { "en-GB", "nl-NL" },
() =>
{
var documentQuery = client
.CreateDocumentQuery<Document>(documentCollection.SelfLink)
.Where(x => x.Created > LastYear);
Console.WriteLine(" {0}", documentQuery);
documentQuery.ToList();
});
Test(
"Via SqlQuerySpec query",
new[] { "en-GB", "nl-NL" },
() =>
{
var sqlQuerySpec = new SqlQuerySpec("SELECT * FROM root WHERE (root.created > @lastYear)");
sqlQuerySpec.Parameters = new SqlParameterCollection();
sqlQuerySpec.Parameters.Add(new SqlParameter("@lastYear", LastYear));
var documentQuery = client.CreateDocumentQuery(documentCollection.SelfLink, sqlQuerySpec);
Console.WriteLine(" {0}", documentQuery);
documentQuery.ToList();
});
Test(
"Via custom generated query",
new[] { "en-GB", "nl-NL" },
() =>
{
var query = $"SELECT * FROM root WHERE (root.created > {LastYear:E10})";
var documentQuery = client.CreateDocumentQuery(documentCollection.SelfLink, query);
Console.WriteLine(" {0}", documentQuery);
documentQuery.ToList();
});
Console.ReadLine();
}
示例2: GetStart
//new add
private static async Task GetStart()
{
var client = new DocumentClient(new Uri(EndpointURL), AuthorizationKey);
database = client.CreateDatabaseQuery().Where(d => d.Id == "ppweict").AsEnumerable().FirstOrDefault();
collection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == "Exam_Pool").AsEnumerable().FirstOrDefault();
var EfDs = client.CreateDocumentQuery(collection.DocumentsLink, "SELECT * FROM Exam_pool f WHERE f.verify = \"true\" ");
foreach (exam_pool EfD in EfDs)
{
Console.WriteLine(EfD);
exams.Add(new exam_pool
{
id = EfD.id,
exam_catrgory = EfD.exam_catrgory,
exam_level = EfD.exam_level,
questions = EfD.questions,
answer_A = EfD.answer_A,
answer_B = EfD.answer_B,
answer_C = EfD.answer_C,
answer_D = EfD.answer_D,
answer_E = EfD.answer_E,
C_answer = EfD.C_answer,
exam_link = EfD.exam_link,
lang = EfD.lang,
verify = EfD.verify,
});
}
}
示例3: UpdateDcAll
public static async Task UpdateDcAll(string endpointUrl, string authorizationKey)
{
DocumentClient client = new DocumentClient(new Uri(endpointUrl), authorizationKey);
var database = await DocumentDB.GetDB(client);
IEnumerable<DocumentCollection> dz = client.CreateDocumentCollectionQuery(database.SelfLink)
.AsEnumerable();
DocumentCollection origin = client.CreateDocumentCollectionQuery(database.SelfLink)
.Where(c => c.Id == "LMSCollection")
.AsEnumerable()
.FirstOrDefault();
//search collection
var ds =
from d in client.CreateDocumentQuery<DcAllocate>(origin.DocumentsLink)
where d.Type == "DisList"
select d;
foreach (var d in ds)
{
if (d.District.Contains("tst-azhang14"))
{
Console.WriteLine(d.DcName);
}
}
/* foreach (var x in dz)
{
Console.WriteLine(x.Id + x.DocumentsLink);
await UpdateDc(x, client, database, origin);
}*/
}
示例4: Main
static void Main(string[] args)
{
ConnectionPolicy policy = new ConnectionPolicy()
{
ConnectionMode = ConnectionMode.Direct,
ConnectionProtocol = Protocol.Tcp
};
Uri endPoint = new Uri(EndpointUrl);
using (DocumentClient client = new DocumentClient(endPoint, AuthKey, policy))
{
Database database =
client.CreateDatabaseQuery().Where(db => db.Id == DatabasebId).AsEnumerable().First();
DocumentCollection collection =
client.CreateDocumentCollectionQuery(database.SelfLink)
.Where(c => c.Id == CollectionId)
.AsEnumerable()
.First();
IEnumerable<DataClass> dataSet = GetDataObjects(100);
Task<ResourceResponse<Document>>[] documentTasks =
dataSet.Select(d => client.CreateDocumentAsync(collection.DocumentsLink, d)).ToArray();
Task.WaitAll(documentTasks);
Document[] docs = documentTasks.Select(t => t.Result.Resource).ToArray();
Document doc = docs.First();
Task<ResourceResponse<Attachment>>[] attachmentTasks =
docs.Select(d => client.CreateAttachmentAsync(doc.AttachmentsLink, GetStream(1024))).ToArray();
Task.WaitAll(attachmentTasks);
DataClass[] data =
client.CreateDocumentQuery<DataClass>(collection.DocumentsLink).Select(d => d).ToArray();
Attachment[] attachments = client.CreateAttachmentQuery(doc.AttachmentsLink).ToArray();
string sql = "SELECT c.Name FROM c Where c.ObjectKey < 30 AND c.ObjectKey > 20";
dynamic[] dataArray = client.CreateDocumentQuery(collection.DocumentsLink, sql).ToArray();
}
}
示例5: Get
public IEnumerable<Trip> Get()
{
var client = new DocumentClient(new Uri("https://etamanager.documents.azure.com:443/"), "HIgfJLkqRsemDoAv62MSn0/UFK2dC9RxtAopuV3rAa7f1tCqou/A2xbh1ShLDkKDaWOPLEsZ0sl7dGzjrEz36A==");
return client.CreateDocumentQuery<Trip>("dbs/-gIgAA==/colls/-gIgALa0OwA=");
//await client.CreateDocumentAsync("dbs/-gIgAA==/colls/-gIgALa0OwA=", new Trip("UKA0021", "EMA", "LHR", "DHL ECO GB", "FL62 ZWB", "25/07/2015 02:04:12", "03:00", "-00:55"));
//return new[]
//{
// new Trip("HDC1001", "HDC", "BRU", "NINATRANS", "NOGPS_Nina", string.Empty, "08:00", "NA"),
// new Trip("UKA0096", "EMA", "LHR", "DHL ECO GB", "LS14 HLK", "25/07/2015 01:36:11", "03:00", "-01:23"),
// new Trip("UKA0021", "EMA", "LHR", "DHL ECO GB", "FL62 ZWB", "25/07/2015 02:04:12", "03:00", "-00:55")
//};
}
示例6: BackupPostCollection
private static async Task BackupPostCollection(DocumentCollection dc, DocumentClient client)
{
Trace.TraceInformation("Collection '{0}' start. Time: '{1}'", dc.Id,
DateTime.Now.ToString(CultureInfo.CurrentCulture));
try
{
var ds =
from d in client.CreateDocumentQuery<PostMessage>(dc.DocumentsLink)
where d.Type == "Post"
select d;
TableBatchOperation batchOperation = new TableBatchOperation();
List<dynamic> docList = new List<dynamic>();
foreach (var d in ds)
{
TablePost c = ModelService.TablePostData(d);
batchOperation.Insert(c);
docList.Add(d);
if (batchOperation.Count == 100)
{
var operation = batchOperation;
var res = await _retryPolicy.ExecuteAsync(
() => _table.ExecuteBatchAsync(operation));
batchOperation = new TableBatchOperation();
if (res.Count == operation.Count)
{
await _iDbService.DocumentDb.BatchDelete(dc, docList);
docList = new List<dynamic>();
Trace.TraceInformation("inserted");
}
}
}
if (batchOperation.Count > 0)
{
var operation = batchOperation;
var res = await _retryPolicy.ExecuteAsync(
() => _table.ExecuteBatchAsync(operation));
if (res.Count == operation.Count)
{
await _iDbService.DocumentDb.BatchDelete(dc, docList);
Trace.TraceInformation("inserted");
}
}
}
catch (Exception e)
{
Trace.TraceError("Error in BackupCollection " + e.Message);
}
}
示例7: Start
public void Start()
{
QueueUtility.Listen<EventController.Position>("PositionQueue", async position =>
{
var client = new DocumentClient(new Uri("https://etamanager.documents.azure.com:443/"), "HIgfJLkqRsemDoAv62MSn0/UFK2dC9RxtAopuV3rAa7f1tCqou/A2xbh1ShLDkKDaWOPLEsZ0sl7dGzjrEz36A==");
var trip = client.CreateDocumentQuery<TripDocument>("dbs/-gIgAA==/colls/-gIgALa0OwA=").Where(t => t.Code == position.TripCode).AsEnumerable().FirstOrDefault();
if (trip != null)
{
trip.ExpectedArrival = position.DT;
await client.ReplaceDocumentAsync(trip.SelfLink, trip);
}
var update = new EventController.ETAUpdate { code = position.TripCode, expectedArrival = position.DT };
QueueUtility.Send("ETAUpdateQueue", update);
});
QueueUtility.Listen<EventController.ETAUpdate>("ETAUpdateQueue", update => this.tripsHub.Clients.All.addNewMessageToPage(update));
}
示例8: RunQuery
private static async void RunQuery()
{
DocumentClient client = new DocumentClient(new Uri(CONST_EndPointUrl), CONST_AuthorizationKey);
Database database = await GetDatabase(client);
DocumentCollection documentCollection = await GetDocumentCollection(client, database);
List<Course> coursesList = client.CreateDocumentQuery<Course>(documentCollection.DocumentsLink).Where(c => c.Name == "English").ToList();
if (coursesList != null && coursesList.Count > 0)
{
foreach (var item in coursesList)
{
Console.WriteLine(item.Name);
}
}
}
示例9: Main
static void Main(string[] args)
{
var query = "SELECT * FROM c";
using (var client = new DocumentClient(new Uri(endpoint), authKey))
{
var collLink = UriFactory.CreateDocumentCollectionUri(databaseId, collectionId);
var querySpec = new SqlQuerySpec { QueryText = query };
var itr = client.CreateDocumentQuery(collLink, querySpec).AsDocumentQuery();
var response = itr.ExecuteNextAsync<Document>().Result;
var charge = response.RequestCharge;
Console.WriteLine("Request charge: {0}", charge);
foreach (var doc in response.AsEnumerable())
{
Console.WriteLine(doc.ToString());
}
}
Console.ReadLine();
}
示例10: Get
// GET /api/search/?criterias=TOTO
public List<FeedItem> Get([FromUri]string criterias = "")
{
// si criterias = LAST10 -> renvoyé les dix derniere articles
var client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey);
Database database = client.CreateDatabaseQuery()
.Where(db => db.Id == databaseId)
.AsEnumerable()
.FirstOrDefault();
DocumentCollection collectionPosts = client.CreateDocumentCollectionQuery(database.CollectionsLink)
.Where(doccoll => doccoll.Id == collectionIdPost)
.AsEnumerable()
.FirstOrDefault();
var posts = (
from b in client.CreateDocumentQuery<FeedItem>(collectionPosts.SelfLink)
where b.Year == 2015 && b.Month >= 1 && b.Day >= 8
select b).ToList();
return posts;
}
示例11: SaveDisList
private static async Task SaveDisList(Hashtable newList, Hashtable oldList,
DocumentCollection origin, DocumentCollection oldDc,
DocumentCollection newDc, DocumentClient client)
{
var t = (long) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
var allow = new DcAllocate
{
Type = "DisList",
DcName = newDc.Id,
DcSelfLink = newDc.SelfLink,
District = new List<string>()
};
foreach (DictionaryEntry i in newList)
{
allow.District.Add(i.Key.ToString());
}
await client.CreateDocumentAsync(origin.DocumentsLink, allow);
var ds =
from d in client.CreateDocumentQuery<DcAllocate>(origin.DocumentsLink)
where d.Type == "DisList" && d.DcName == oldDc.Id
select d;
var l = ds.ToList().FirstOrDefault();
if (l != null) await client.DeleteDocumentAsync(l._self);
var allow2 = new DcAllocate
{
Type = "DisList",
DcName = oldDc.Id,
DcSelfLink = oldDc.SelfLink,
District = new List<string>(),
};
foreach (DictionaryEntry i in oldList)
{
allow2.District.Add(i.Key.ToString());
}
await client.CreateDocumentAsync(origin.DocumentsLink, allow2);
}
示例12: sp2
private static async Task sp2(DocumentCollection dc, DocumentClient client, Database database)
{
DocumentCollection dc2 = client.CreateDocumentCollectionQuery(database.SelfLink)
.Where(c => c.Id == "LMSCollection1444075919174")
.AsEnumerable()
.FirstOrDefault();
await client.OpenAsync();
//await _iDbService.CollectionTransfer(client, dc2, dc);
var mn=await client.ReadDatabaseAsync(database.SelfLink);
/* await client.CreateDocumentAsync(dc.SelfLink, new CurrentCollection
{
id = "CurrentCollection",
name=dc.Id
});*/
/* var resolver = _iDbService.GetResolver(client, dc);
foreach (var d in resolver.PartitionMap)
{
Console.WriteLine(d.Value);
Offer offer = client.CreateOfferQuery()
.Where(r => r.ResourceLink == d.Value)
.AsEnumerable()
.SingleOrDefault();
}*/
/* HashPartitionResolver hashResolver = new HashPartitionResolver(
u => ((PostMessage) u).Path.District,
new string[] {dc.SelfLink, dc2.SelfLink});
client.PartitionResolvers[database.SelfLink] = hashResolver;*/
var rangeResolver = _iDbService.GetResolver(client);
client.PartitionResolvers[database.SelfLink] = rangeResolver;
var created = await _iDbService.InitResolver("");
while (true)
{
var re2 = await _iDbService.UpdateResolver(dc2);
var p = re2;
await Task.Delay(TimeSpan.FromSeconds(4));
}
var z1 = rangeResolver.GetPartitionKey(new PostMessage
{
Type = "Post",
Info = new Info
{
user = "tzk",
uid = "1210808",
message = "java",
timestamp = 7
},
Path = new PostPath
{
District = "tst-azhang"
}
});
//search global
IQueryable<PostMessage> query = client.CreateDocumentQuery<PostMessage>(database.SelfLink)
.Where(u => u.Info.timestamp>1);
var now = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
//search on partition
var t1 = DateTime.Now;
var query2 = client.CreateDocumentQuery<PostMessage>(database.SelfLink, new FeedOptions
{
MaxItemCount = 1200
}, now);
var query3 = client.CreateDocumentQuery<PostMessage>(dc2.SelfLink).AsDocumentQuery();
var t2 = DateTime.Now;
Console.WriteLine(t2-t1);
//.Where(u => u.Path.District=="tst-azhang");
foreach (PostMessage a in query2)
{
Console.WriteLine(a.Info.timestamp);
}
/* double totalRequestCharge = 0;
while (query3.HasMoreResults)
{
FeedResponse<dynamic> queryResponse = await query3.ExecuteNextAsync<dynamic>();
Console.WriteLine("Query batch consumed {0} request units {1} doc", queryResponse.RequestCharge, queryResponse.Count);
totalRequestCharge += queryResponse.RequestCharge;
}
Console.WriteLine(DateTime.Now - t2);
Console.WriteLine("Query consumed {0} request units in total", totalRequestCharge);*/
//.........这里部分代码省略.........
示例13: DeleteAll
private static async Task DeleteAll(DocumentClient client, Database database,
DocumentCollection documentCollection)
{
IEnumerable<DocumentCollection> dz = client.CreateDocumentCollectionQuery(database.SelfLink)
.AsEnumerable();
foreach (var z in dz)
{
var families =
from f in client.CreateDocumentQuery(z.DocumentsLink)
select f;
foreach (var family in families)
{
dynamic d = JsonConvert.DeserializeObject(family.ToString());
//Console.WriteLine(d.Path.school);
try
{
//var res = await client.DeleteDocumentAsync(family.SelfLink);
var family1 = family;
var response = await _iDbService.ExecuteWithRetries(5, () => client.DeleteDocumentAsync(family1.SelfLink));
}
catch (DocumentClientException e)
{
/* if (e.RetryAfter.TotalMilliseconds>0)
{
Console.WriteLine(e.RetryAfter.TotalMilliseconds);
Thread.Sleep((int) e.RetryAfter.TotalMilliseconds);
client.DeleteDocumentAsync(family.SelfLink).Wait();
}
else
{*/
Console.WriteLine(e.Message);
// }
}
Console.WriteLine(family.SelfLink);
}
}
}
示例14: InternalGetSiteClassificationByName
private SiteClassification InternalGetSiteClassificationByName(DocumentClient client, string collectionLink, string name)
{
var _siteClassification = from record in client.CreateDocumentQuery<SiteClassification>(collectionLink)
where record.Key == name
select record;
return _siteClassification.ToList().FirstOrDefault();
}
示例15: GetStartedDemo
private static async Task GetStartedDemo()
{
// Create a new instance of the DocumentClient
var client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey);
// Check to verify a database with the id=FamilyRegistry does not exist
Database database = client.CreateDatabaseQuery().Where(db => db.Id == "FamilyRegistry").AsEnumerable().FirstOrDefault();
// If the database does not exist, create a new database
if (database == null)
{
database = await client.CreateDatabaseAsync(
new Database
{
Id = "FamilyRegistry"
});
WriteMessage("Created dbs/FamilyRegistry");
}
// Check to verify a document collection with the id=FamilyCollection does not exist
DocumentCollection documentCollection = client.CreateDocumentCollectionQuery("dbs/" + database.Id).Where(c => c.Id == "FamilyCollection").AsEnumerable().FirstOrDefault();
// If the document collection does not exist, create a new collection
if (documentCollection == null)
{
documentCollection = await client.CreateDocumentCollectionAsync("dbs/" + database.Id,
new DocumentCollection
{
Id = "FamilyCollection"
});
WriteMessage("Created dbs/FamilyRegistry/colls/FamilyCollection");
}
// Check to verify a document with the id=AndersenFamily does not exist
Document document = client.CreateDocumentQuery("dbs/" + database.Id + "/colls/" + documentCollection.Id).Where(d => d.Id == "AndersenFamily").AsEnumerable().FirstOrDefault();
// If the document does not exist, create a new document
if (document == null)
{
// Create the Andersen Family document
Family andersonFamily = new Family
{
Id = "AndersenFamily",
LastName = "Andersen",
Parents = new Parent[] {
new Parent { FirstName = "Thomas" },
new Parent { FirstName = "Mary Kay"}
},
Children = new Child[] {
new Child
{
FirstName = "Henriette Thaulow",
Gender = "female",
Grade = 5,
Pets = new Pet[] {
new Pet { GivenName = "Fluffy" }
}
}
},
Address = new Address { State = "WA", County = "King", City = "Seattle" },
IsRegistered = true
};
// id based routing for the first argument, "dbs/FamilyRegistry/colls/FamilyCollection"
await client.CreateDocumentAsync("dbs/" + database.Id + "/colls/" + documentCollection.Id, andersonFamily);
WriteMessage("Created dbs/FamilyRegistry/colls/FamilyCollection/docs/AndersenFamily");
}
// Check to verify a document with the id=AndersenFamily does not exist
document = client.CreateDocumentQuery("dbs/" + database.Id + "/colls/" + documentCollection.Id).Where(d => d.Id == "WakefieldFamily").AsEnumerable().FirstOrDefault();
if (document == null)
{
// Create the WakeField document
Family wakefieldFamily = new Family
{
Id = "WakefieldFamily",
Parents = new Parent[] {
new Parent { FamilyName= "Wakefield", FirstName= "Robin" },
new Parent { FamilyName= "Miller", FirstName= "Ben" }
},
Children = new Child[] {
new Child {
FamilyName= "Merriam",
FirstName= "Jesse",
Gender= "female",
Grade= 8,
Pets= new Pet[] {
new Pet { GivenName= "Goofy" },
new Pet { GivenName= "Shadow" }
}
},
new Child {
FamilyName= "Miller",
FirstName= "Lisa",
Gender= "female",
Grade= 1
//.........这里部分代码省略.........