本文整理汇总了C#中TSqlObject.GetReferenced方法的典型用法代码示例。如果您正苦于以下问题:C# TSqlObject.GetReferenced方法的具体用法?C# TSqlObject.GetReferenced怎么用?C# TSqlObject.GetReferenced使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TSqlObject
的用法示例。
在下文中一共展示了TSqlObject.GetReferenced方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDataType
private SqlDataType GetDataType(TSqlObject something)
{
TSqlObject dataType = something.GetReferenced(Column.DataType).SingleOrDefault();
if (dataType == null)
{
return SqlDataType.Unknown;
}
// Some data types don't cleanly convert
switch (dataType.Name.Parts.Last())
{
case "hierarchyid":
case "geometry":
case "geography":
return SqlDataType.Variant;
}
// Note: User Defined Data Types (UDDTs) are not supported during deployment of memory optimized tables.
// The code below handles UDDTs in order to show how properties of a UDDT should be accessed and because
// the model validation does not actually block this syntax at present there are tests that validate this behavior.
// User Defined Data Types and built in types are merged in the public model.
// We want to examine the built in type: for user defined data types this will be
// found by accessing the DataType.Type object, which will not exist for a built in type
TSqlObject builtInType = dataType.GetReferenced(DataType.Type).SingleOrDefault();
if (builtInType != null)
{
dataType = builtInType;
}
return dataType.GetProperty<SqlDataType>(DataType.SqlDataType);
}
示例2: OnAnalyze
protected override IEnumerable<SqlRuleProblem> OnAnalyze(string name, TSqlObject table)
{
//Get the columns of the table
var columns = table.GetReferenced(Table.Columns);
if (columns.Count() == 0)
yield return new SqlRuleProblem(string.Format("The link table {0} has no column", name), table);
//Ensure that one of them is effecively a DateId
var timeBasedColumn = columns.FirstOrDefault(i => i.Name.Parts.Last() == Configuration.TimeBased.Key);
if (timeBasedColumn == null)
yield return new SqlRuleProblem(string.Format("No column named '{0}' for link table {1}", Configuration.TimeBased.Key, name), table);
}
示例3: OnAnalyze
protected override IEnumerable<SqlRuleProblem> OnAnalyze(string name, TSqlObject table)
{
var indexes = table.GetReferencing(Index.IndexedObject);
var timeBasedIndexes = indexes.Where(i => i.GetReferenced(Index.Columns).First().Name.Parts.Last()
== Configuration.TimeBased.Key);
if (timeBasedIndexes.Count() == 0)
yield return new SqlRuleProblem(string.Format("No index where first column is '{0}' for link table {1}", Configuration.TimeBased.Key, name), table);
foreach (var tbIndex in timeBasedIndexes)
{
var unexpectedColumns = tbIndex.GetReferenced(Index.Columns).Where(c => c.Name.Parts.Last() != Configuration.TimeBased.Key);
if (unexpectedColumns.Count()>0)
{
yield return new SqlRuleProblem(
string.Format(
"The time-based index '{0}' for link table '{1}' contains additional columns. Unexpected column{2} '{3}'"
, tbIndex.Name
, name
, (unexpectedColumns.Count() == 1) ? " is " : "s are "
, string.Join("', '", unexpectedColumns.Select(c => c.Name.Parts.Last()))
), table);
}
var idColumns = table.GetReferenced(Table.Columns).Where(c => c.Name.Parts.Last() != Configuration.TimeBased.Key && c.Name.Parts.Last().EndsWith("Id"));
var includedColumns = tbIndex.GetReferenced(Index.IncludedColumns);
var missingColumns = idColumns.Except(includedColumns);
if (missingColumns.Count()>0)
{
yield return new SqlRuleProblem(
string.Format(
"The time-based index '{0}' for link table '{1}' doesn't include some Id columns. Missing column{2} '{3}'"
, tbIndex.Name
, name
, (missingColumns.Count() == 1) ? " is " : "s are "
, string.Join("', '", missingColumns.Select(c => c.Name.Parts.Last()))
), table);
}
}
}
示例4: OnAnalyze
protected override IEnumerable<SqlRuleProblem> OnAnalyze(string name, TSqlObject table)
{
//Get the columns of the table
var columns = table.GetReferenced(Table.Columns);
if (columns.Count() == 0)
yield return new SqlRuleProblem(string.Format("The info table {0} has no column", name), table);
//Ensure that one of them is effecively an identity
var identityColumn = columns.FirstOrDefault(c => c.GetProperty<bool>(Column.IsIdentity));
if (identityColumn == null)
yield return new SqlRuleProblem(string.Format("No identity column for the info table {0}", name), table);
else
{
if (!string.IsNullOrEmpty(Configuration.Info.IdentityNamingConvention))
{
//Ensure that this column has correct naming convention
var actualIdentityColumnName = identityColumn.Name.Parts.Last();
var expectedIdentityColumnName = string.Format(Configuration.Info.IdentityNamingConvention, table.Name.Parts.Last());
if (string.Compare(actualIdentityColumnName, expectedIdentityColumnName, false) != 0)
yield return new SqlRuleProblem(string.Format("Identity column for the info table {0} doesn't follow the naming convention: '{1}' in place of '{2}'", name, actualIdentityColumnName, expectedIdentityColumnName), table);
}
}
}
示例5: GetSchemaForColumn
private static ColumnInfo GetSchemaForColumn(TSqlObject model)
{
TSqlObject type = model.GetReferenced(Column.DataType).First();
string dataType = type.Name.Parts[0];
bool isNullable = model.GetProperty<bool>(Column.Nullable);
int length = model.GetProperty<int>(Column.Length);
return new ColumnInfo
{
Name = model.Name.Parts[2],
FullName = model.Name.ToString(),
SqlDataType = dataType,
ClrType = GetTypeMapping(dataType, isNullable),
Nullable = isNullable,
Length = length
};
}
示例6: GetSchemaForView
private static ViewInfo GetSchemaForView(TSqlObject model)
{
ViewInfo retVal = new ViewInfo();
retVal.ShortName = model.Name.Parts[1];
retVal.FullName = model.Name.ToString();
var columns = model.GetReferenced(View.Columns).ToArray();
retVal.Columns = new ColumnInfo[columns.Length];
for (int i = 0; i < columns.Length; i++)
{
TSqlObject column = columns[i];
string dataType = "nvarchar";
bool isNullable = column.GetProperty<bool>(Column.Nullable);
int length = column.GetProperty<int>(Column.Length);
TSqlObject referencedColumn = column.GetReferenced().FirstOrDefault();
if (null != referencedColumn)
{
TSqlObject type = referencedColumn.GetReferenced(Column.DataType).First();
dataType = type.Name.Parts[0];
}
retVal.Columns[i] = new ColumnInfo
{
Name = column.Name.Parts[2],
FullName = column.Name.ToString(),
SqlDataType = dataType,
ClrType = GetTypeMapping(dataType, isNullable),
Nullable = isNullable,
Length = length
};
}
return retVal;
}
示例7: GetSchemaForTable
private static TableInfo GetSchemaForTable(TSqlObject model)
{
TableInfo retVal = new TableInfo();
retVal.EntityName = _pluralizationService.Singularize(model.Name.Parts[1]);
retVal.ShortName = model.Name.Parts[1];
retVal.FullName = model.Name.ToString();
var columns = model.GetReferenced(Table.Columns).ToArray();
retVal.Columns = new ColumnInfo[columns.Length];
for (int i = 0; i < columns.Length; i++)
{
ColumnInfo column = GetSchemaForColumn(columns[i]);
retVal.Columns[i] = column;
if (columns[i].GetProperty<bool>(Column.IsIdentity))
retVal.IdentityColumn = column;
}
return retVal;
}
示例8: AddPropertiesForColumn
private void AddPropertiesForColumn(Panel panel, TSqlObject column)
{
var type = column.GetMetadata<ColumnType>(Column.ColumnType);
panel.Children.Add(GetPropertyLabel("Column MetaType: ", type == ColumnType.Column ? "Standard Column" : type.ToString()));
foreach (TSqlObject referenced in column.GetReferenced())
{
panel.Children.Add(GetPropertyLabel("Type: ", referenced.Name.ToString()));
}
}
示例9: IsIndexOnMemoryOptimizedTable
private static bool IsIndexOnMemoryOptimizedTable(TSqlObject index)
{
TSqlObject targetTable = index.GetReferenced(Index.IndexedObject).SingleOrDefault();
return targetTable != null
&& Table.TypeClass.Equals(targetTable.ObjectType)
&& targetTable.GetProperty<bool>(Table.MemoryOptimized);
}
示例10: IsCharacterColumn
private static bool IsCharacterColumn(TSqlObject column)
{
TSqlObject dataType = column.GetReferenced(Column.DataType).SingleOrDefault();
if (dataType == null)
{
return false;
}
// Note: User Defined Data Types (UDDTs) are not supported during deployment of memory optimized tables.
// The code below handles UDDTs in order to show how properties of a UDDT should be accessed and because
// the model validation does not actually block this syntax at present there are tests that validate this behavior.
// User Defined Data Types and built in types are merged in the public model.
// We want to examine the built in type: for user defined data types this will be
// found by accessing the DataType.Type object, which will not exist for a built in type
TSqlObject builtInType = dataType.GetReferenced(DataType.Type).SingleOrDefault();
if (builtInType != null)
{
dataType = builtInType;
}
SqlDataType sqlDataType = dataType.GetProperty<SqlDataType>(DataType.SqlDataType);
return CharacterDataTypes.Contains(sqlDataType);
}
示例11: AnalyzeColumns
private static void AnalyzeColumns(
SqlRuleExecutionContext context,
TSqlObject index,
string defaultCollation,
IList<SqlRuleProblem> problems)
{
foreach (TSqlObject column in index.GetReferenced(Index.Columns)
.Where(column => IsCharacterColumn(column)))
{
// Fall back on the default project collation if none is defined for the specific column
string collation = column.GetProperty<string>(Column.Collation) ?? defaultCollation ?? string.Empty;
if (!collation.EndsWith(Bin2Ending, StringComparison.OrdinalIgnoreCase))
{
// Error looks liks "Index <name> on column <name> should have a BIN2 collation instead of <collation>"
// Choosing to add 1 problem per-column. This will cause more warnings in the error manager but is more precise
string errorMsg = string.Format(CultureInfo.CurrentCulture,
context.RuleDescriptor.DisplayDescription,
RuleUtils.GetElementName(index, context, ElementNameStyle.EscapedFullyQualifiedName),
RuleUtils.GetElementName(column, context, ElementNameStyle.EscapedFullyQualifiedName),
collation);
SqlRuleProblem problem = new SqlRuleProblem(errorMsg, index);
problems.Add(problem);
}
}
}