本文整理汇总了C#中IDocumentStore.Query方法的典型用法代码示例。如果您正苦于以下问题:C# IDocumentStore.Query方法的具体用法?C# IDocumentStore.Query怎么用?C# IDocumentStore.Query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocumentStore
的用法示例。
在下文中一共展示了IDocumentStore.Query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public Task Run(IDocumentStore store)
{
var logger = store.Configuration.Logger;
var configuration = store.Configuration;
if (!configuration.RunDocumentMigrationsOnStartup)
return Task.FromResult(0);
return Task.Factory.StartNew(() =>
{
var migrator = new DocumentMigrator(configuration);
foreach (var table in configuration.Tables.Values.OfType<DocumentTable>())
{
var baseDesign = configuration.TryGetDesignByTablename(table.Name);
if (baseDesign == null)
{
throw new InvalidOperationException($"Design not found for table '{table.Name}'");
}
while (true)
{
QueryStats stats;
var rows = store
.Query(table, out stats,
@where: "AwaitsReprojection = @AwaitsReprojection or Version < @version",
@select: "Id, AwaitsReprojection, Version, Discriminator, Etag",
take: 100,
@orderby: "newid()",
parameters: new { AwaitsReprojection = true, version = configuration.ConfiguredVersion })
.ToList();
if (stats.TotalResults == 0) break;
logger.Information("Found {0} document that must be migrated.", stats.TotalResults);
foreach (var row in rows)
{
var key = (string)row[table.IdColumn];
var currentDocumentVersion = (int)row[table.VersionColumn];
var discriminator = ((string)row[table.DiscriminatorColumn]).Trim();
var concreteDesign = store.Configuration.GetOrCreateDesignByDiscriminator(baseDesign, discriminator);
var shouldUpdate = false;
if ((bool)row[table.AwaitsReprojectionColumn])
{
shouldUpdate = true;
logger.Information("Reprojection document {0}/{1}.",
concreteDesign.DocumentType.FullName, key, currentDocumentVersion, configuration.ConfiguredVersion);
}
if (migrator.ApplicableCommands(concreteDesign, currentDocumentVersion).Any())
{
shouldUpdate = true;
}
if (shouldUpdate)
{
try
{
using (var session = new DocumentSession(store))
{
session.Load(concreteDesign.DocumentType, key);
session.SaveChanges(lastWriteWins: false, forceWriteUnchangedDocument: true);
}
}
catch (ConcurrencyException) { }
catch (Exception exception)
{
logger.Error(exception, "Error while migrating document of type {0} with id {1}.", concreteDesign.DocumentType.FullName, key);
Thread.Sleep(100);
}
}
else
{
logger.Information("Document did not change.");
var projection = new Dictionary<string, object>
{
{table.VersionColumn, configuration.ConfiguredVersion}
};
store.Update(table, key, (Guid)row[table.EtagColumn], projection);
}
}
}
}
}, TaskCreationOptions.LongRunning);
}