示例#1
0
        private static DataFieldMapTable GetMapTableByColumnNames <TEntity>(TEntity entity, MetaDataTable metaDataTable,
                                                                            params string[] columnNames)
        {
            DataFieldMapTable mapTable = new DataFieldMapTable(columnNames.Length);

            foreach (string columnName in columnNames)
            {
                string colName = columnName.Trim().ToLower();
                if (!metaDataTable.Columns.ContainsKey(colName) ||
                    IsIgnored(metaDataTable.Columns[colName]))
                {
                    continue;
                }

                var metaColumn = metaDataTable.Columns[colName];
                mapTable.Add(metaColumn.Name, GetColumnValue(metaColumn, entity));
            }

            return(mapTable);
        }
示例#2
0
        /// <summary>
        /// 获取实体属性与值的对应表集合。
        /// </summary>
        /// <typeparam name="TEntity">实体对象类型</typeparam>
        /// <param name="entity">实体对象</param>
        /// <param name="entityName">实体名称</param>
        /// <param name="columnNames">属性列名称</param>
        /// <returns>实体属性与值的对应表集合</returns>
        public static DataFieldMapTable GetMapTable <TEntity>(TEntity entity, string entityName, params string[] columnNames)
        {
            var metaDataTable = new MetaDataTable(typeof(TEntity), entityName);

            if (columnNames != null && columnNames.Length > 0)
            {
                return(GetMapTableByColumnNames <TEntity>(entity, metaDataTable, columnNames));
            }

            DataFieldMapTable mapTable = new DataFieldMapTable(metaDataTable.Columns.Count);

            foreach (string key in metaDataTable.Columns.Keys)
            {
                var metaColumn = metaDataTable.Columns[key];
                if (IsIgnored(metaColumn))
                {
                    continue;
                }

                mapTable.Add(metaColumn.Name, GetColumnValue(metaColumn, entity));
            }

            return(mapTable);
        }