本文整理汇总了C#中IReadOnlyCollection.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# IReadOnlyCollection.OfType方法的具体用法?C# IReadOnlyCollection.OfType怎么用?C# IReadOnlyCollection.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReadOnlyCollection
的用法示例。
在下文中一共展示了IReadOnlyCollection.OfType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteCommands
public IReadOnlyCollection<IEvent> ExecuteCommands(IReadOnlyCollection<ICommand> commands)
{
if (commands.OfType<DropViewsCommand>().Any())
{
var database = _sqlConnection.GetDatabase();
var views = database.Views.Cast<View>().Where(v => v != null && !v.IsSystemObject).ToArray();
var viewsToRestore = new List<StringCollection>();
foreach (var view in views)
{
viewsToRestore.Add(view.Script());
view.Drop();
}
return new[] { new ViewsDroppedEvent(viewsToRestore) };
}
var restoreViewsCommand = commands.OfType<RestoreViewsCommand>().SingleOrDefault();
if (restoreViewsCommand != null)
{
foreach (var view in restoreViewsCommand.ViewsToRestore)
{
foreach (var script in view)
{
var command = new SqlCommand(script, _sqlConnection) { CommandTimeout = _commandTimeout };
command.ExecuteNonQuery();
}
}
}
return Array.Empty<IEvent>();
}
示例2: ExecuteCommands
public IReadOnlyCollection<IEvent> ExecuteCommands(IReadOnlyCollection<ICommand> commands)
{
if (commands.OfType<DisableConstraintsCommand>().Any())
{
var tables = GetTables();
var checks = tables.SelectMany(x => x.Checks.Cast<Check>()).ToArray();
var checksToRestore = new List<StringCollection>();
foreach (var check in checks)
{
checksToRestore.Add(check.Script());
check.Drop();
}
var foreignKeys = tables.SelectMany(x => x.ForeignKeys.Cast<ForeignKey>()).ToArray();
var foreignKeysToRestore = new List<StringCollection>();
foreach (var foreignKey in foreignKeys)
{
foreignKeysToRestore.Add(foreignKey.Script());
foreignKey.Drop();
}
return new[] { new ConstraintsDisabledEvent(checksToRestore, foreignKeysToRestore) };
}
var enableCommand = commands.OfType<EnableConstraintsCommand>().SingleOrDefault();
if (enableCommand != null)
{
foreach (var check in enableCommand.ChecksToRestore)
{
foreach (var script in check)
{
var command = new SqlCommand(script, _sqlConnection) { CommandTimeout = _commandTimeout };
command.ExecuteNonQuery();
}
}
foreach (var foreinKey in enableCommand.ForeignKeysToRestore)
{
foreach (var script in foreinKey)
{
var command = new SqlCommand(script, _sqlConnection) { CommandTimeout = _commandTimeout };
command.ExecuteNonQuery();
}
}
}
return Array.Empty<IEvent>();
}
示例3: ExecuteCommands
public IReadOnlyCollection<IEvent> ExecuteCommands(IReadOnlyCollection<ICommand> commands)
{
var command = commands.OfType<TruncateTableCommand>().SingleOrDefault();
if (command != null)
{
ExecuteTruncate(command.Table);
}
return Array.Empty<IEvent>();
}
示例4: ExecuteCommands
public IReadOnlyCollection<IEvent> ExecuteCommands(IReadOnlyCollection<ICommand> commands)
{
var enableCommand = commands.OfType<EnableIndexesCommand>().SingleOrDefault();
if (enableCommand != null)
{
_indexManager.EnableIndexes(enableCommand.Table);
}
return Array.Empty<IEvent>();
}
示例5: ExecuteCommands
public IReadOnlyCollection<IEvent> ExecuteCommands(IReadOnlyCollection<ICommand> commands)
{
var command = commands.OfType<UpdateTableStatisticsCommand>().SingleOrDefault();
if (command == null)
{
return Array.Empty<IEvent>();
}
try
{
var database = _sqlConnection.GetDatabase();
var table = string.IsNullOrEmpty(command.Table.Schema) ? database.Tables[command.Table.Table] : database.Tables[command.Table.Table, command.Table.Schema];
table.UpdateStatistics();
return Array.Empty<IEvent>();
}
catch (Exception ex)
{
throw new DataException($"Error occured while statistics updating for table {command.Table}", ex);
}
}
示例6: BuildColumnExpression
private Expression BuildColumnExpression(
IReadOnlyCollection<Expression> projections,
TableExpressionBase tableExpression,
IProperty property,
IQuerySource querySource)
{
Check.NotNull(property, nameof(property));
if (projections.Count == 0)
{
return new ColumnExpression(
_relationalAnnotationProvider.For(property).ColumnName,
property,
tableExpression);
}
var aliasExpressions
= projections
.OfType<AliasExpression>()
.Where(p => p.TryGetColumnExpression()?.Property == property)
.ToList();
var aliasExpression
= aliasExpressions.Count == 1
? aliasExpressions[0]
: aliasExpressions.Last(ae => ae.TryGetColumnExpression().Table.QuerySource == querySource);
return new ColumnExpression(
aliasExpression.Alias ?? aliasExpression.TryGetColumnExpression().Name,
property,
tableExpression);
}
示例7: BuildColumnExpression
private Expression BuildColumnExpression(
IReadOnlyCollection<Expression> projections,
TableExpressionBase tableExpression,
IProperty property)
{
Check.NotNull(property, nameof(property));
if (projections.Count == 0)
{
return new ColumnExpression(
_queryCompilationContext.GetColumnName(property),
property,
tableExpression);
}
var matchingColumnExpression
= projections
.OfType<AliasExpression>()
.Last(p => p.TryGetColumnExpression()?.Property == property);
return new ColumnExpression(
matchingColumnExpression.Alias ?? matchingColumnExpression.TryGetColumnExpression().Name,
property,
tableExpression);
}
示例8: CreateSchemaChangesCompensationalCommands
private static IReadOnlyCollection<ICommand> CreateSchemaChangesCompensationalCommands(IReadOnlyCollection<IEvent> events)
{
var commands = new List<ICommand>();
var constraintsDisabledEvent = events.OfType<ConstraintsDisabledEvent>().SingleOrDefault();
if (constraintsDisabledEvent != null)
{
commands.Add(new EnableConstraintsCommand(constraintsDisabledEvent.Checks, constraintsDisabledEvent.ForeignKeys));
}
var viewsDroppedEvent = events.OfType<ViewsDroppedEvent>().SingleOrDefault();
if (viewsDroppedEvent != null)
{
commands.Add(new RestoreViewsCommand(viewsDroppedEvent.ViewsToRestore));
}
return commands;
}
示例9: HandleAia
private IReadOnlyCollection<ILaunchableContent> HandleAia(
IReadOnlyCollection<ILaunchableContent> content) {
var info = new AiaInfo(content.OfType<IHavePackageName>().ToArray());
var newModsList = content.ToList();
if (info.HasAia() && info.HasCup()) {
// if (aiaSpecific != null || aiaSpecificLite != null)
// newModsList.Remove(Cup);
// else
newModsList.RemoveAll(info.IsAia);
}
if (info.HasCup() || info.HasAia())
newModsList.RemoveAll(info.IsA3Mp);
return newModsList;
}