コード例 #1
0
        private PrimaryKey FetchPrimary(int tableId)
        {
            var indexRows = ConstraintInformation
                            .Where(x => x.Index.object_id == tableId && x.Index.is_primary_key.Equals("True", StringComparison.OrdinalIgnoreCase))
                            .GroupBy(x => x.Index.name);
            var index = indexRows.FirstOrDefault();

            if (index != null)
            {
                var resultIndex = index.FirstOrDefault()?.Index;
                if (resultIndex != null)
                {
                    resultIndex.Columns = index.ToList().OrderBy(x => x.IndexColumn.key_ordinal)
                                          .Select(x => x.SystemColumn.name)
                                          .Aggregate((x, y) => x + "|" + y).Trim('|');
                }
                var primaryKeys = resultIndex.MapTo <PrimaryKey>();
                var constraint  = KeyConstraints.FirstOrDefault(x => x.name == primaryKeys.Name);
                if (constraint != null)
                {
                    primaryKeys.is_system_named = constraint.is_system_named;
                }
                return(primaryKeys);
            }

            return(null);
        }
コード例 #2
0
        private List <Index> FetchIndexes(int tableId)
        {
            var indexRows = ConstraintInformation
                            .Where(x => x.Index.object_id == tableId && x.Index.is_primary_key.Equals("False", StringComparison.OrdinalIgnoreCase))
                            .GroupBy(x => x.Index.name);
            var existsIndex = new List <Index>();

            foreach (var index in indexRows)
            {
                var resultIndex = index.FirstOrDefault()?.Index;
                if (resultIndex != null)
                {
                    resultIndex.Columns = index.ToList().OrderBy(x => x.IndexColumn.key_ordinal)
                                          .Select(x => x.SystemColumn.name)
                                          .Aggregate((x, y) => x + "|" + y).Trim('|');
                }
                existsIndex.Add(resultIndex);
            }

            return(existsIndex);
        }