当前位置: 首页>>代码示例>>C#>>正文


C# TableSchema.GetColumn方法代码示例

本文整理汇总了C#中TableSchema.GetColumn方法的典型用法代码示例。如果您正苦于以下问题:C# TableSchema.GetColumn方法的具体用法?C# TableSchema.GetColumn怎么用?C# TableSchema.GetColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TableSchema的用法示例。


在下文中一共展示了TableSchema.GetColumn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Join

        /// <summary>
        /// Initializes a new instance of the <see cref="Join"/> class.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="joinType">Type of the join.</param>
        public Join(TableSchema.Table from, TableSchema.Table to, JoinType joinType,params string[] joinExpressions)
        {
            TableSchema.TableColumn fromCol = null;
            TableSchema.TableColumn toCol = null;
            if (joinExpressions != null && joinExpressions.Length > 0)
                JoinExpressions.AddRange(joinExpressions);
            foreach(TableSchema.TableColumn col in from.Columns)
            {
                if(col.IsForeignKey && !String.IsNullOrEmpty(col.ForeignKeyTableName))
                {
                    //TableSchema.Table fkTable = col.Table.Provider.GetTableSchema(col.ForeignKeyTableName, col.Table.TableType);
                    TableSchema.Table fkTable = DataService.GetSchema(col.ForeignKeyTableName, col.Table.Provider.Name, col.Table.TableType);
                    if(Utility.IsMatch(fkTable.Name, to.Name))
                    {
                        fromCol = col;
                        //found it - use the PK
                        toCol = fkTable.PrimaryKey;
                        break;
                    }
                }
            }

            //reverse it - just in case we can't find a match
            if(fromCol == null || toCol == null)
            {
                foreach(TableSchema.TableColumn col in to.Columns)
                {
                    if(col.IsForeignKey && !String.IsNullOrEmpty(col.ForeignKeyTableName))
                    {
                        //TableSchema.Table fkTable = col.Table.Provider.GetTableSchema(col.ForeignKeyTableName, col.Table.TableType);
                        TableSchema.Table fkTable = DataService.GetSchema(col.ForeignKeyTableName, col.Table.Provider.Name, col.Table.TableType);
                        if(Utility.IsMatch(fkTable.Name, from.Name))
                        {
                            toCol = col;
                            //found it - use the PK
                            fromCol = fkTable.PrimaryKey;
                            break;
                        }
                    }
                }
            }

            //if that fails, see if there is a matching column name
            if(fromCol == null || toCol == null)
            {
                //first, try to match the PK on the from table
                //to a column in the "to" table
                if(to.Columns.Contains(from.PrimaryKey.ColumnName))
                {
                    FromColumn = from.PrimaryKey;
                    ToColumn = to.GetColumn(from.PrimaryKey.ColumnName);
                    //if that doesn't work, see if the PK of the "to" table has a
                    //matching column in the "from" table
                }
                else if(from.Columns.Contains(to.PrimaryKey.ColumnName))
                {
                    FromColumn = from.GetColumn(to.PrimaryKey.ColumnName);
                    ToColumn = to.PrimaryKey;
                }
            }

            //if that fails - run a match on any column that matches in "from" to "to"
            if(fromCol == null || toCol == null)
            {
                foreach(TableSchema.TableColumn col in from.Columns)
                {
                    if(to.Columns.Contains(col.ColumnName))
                    {
                        toCol = to.GetColumn(col.ColumnName);
                        fromCol = col;
                        break;
                    }
                }
            }

            //still null? this seems exhausting, but the good thing is that these are indexed loops
            //so they execute fast :)
            if(fromCol == null || toCol == null)
            {
                foreach(TableSchema.TableColumn col in to.Columns)
                {
                    if(from.Columns.Contains(col.ColumnName))
                    {
                        fromCol = from.GetColumn(col.ColumnName);
                        toCol = col;
                        break;
                    }
                }
            }

            //if it's still null, throw since the join can't be made
            //and that's a failure of this method
            if(fromCol == null || toCol == null)
            {
//.........这里部分代码省略.........
开发者ID:eleooo,项目名称:App,代码行数:101,代码来源:Join.cs


注:本文中的TableSchema.GetColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。