using System.Collections.Immutable; using System.Data; using Connected.Data.Schema.Sql; using Connected.Entities.Annotations; namespace Connected.Data.Schema; internal class ExistingColumn : ISchemaColumn, IExistingSchemaColumn { public ExistingColumn(ISchema schema) { Schema = schema; } private ISchema Schema { get; } public string Name { get; set; } public DbType DataType { get; set; } public bool IsIdentity { get; set; } public bool IsVersion { get; set; } public bool IsUnique { get; set; } public bool IsIndex { get; set; } public bool IsPrimaryKey { get; set; } public string DefaultValue { get; set; } public int MaxLength { get; set; } public bool IsNullable { get; set; } public string DependencyType { get; set; } public string DependencyProperty { get; set; } public string Index { get; set; } public int Precision { get; set; } public int Scale { get; set; } public DateKind DateKind { get; set; } = DateKind.DateTime; public BinaryKind BinaryKind { get; set; } = BinaryKind.VarBinary; public int DatePrecision { get; set; } public ImmutableArray QueryIndexColumns(string column) { if (Schema is not ExistingSchema existing) return ImmutableArray.Empty; foreach (var index in existing.Indexes) { if (index.Columns.Contains(column, StringComparer.OrdinalIgnoreCase)) return index.Columns.ToImmutableArray(); } return ImmutableArray.Empty; } }