コード例 #1
0
        public EntityDataReader(IEnumerable <T> col, EntityDataReaderOptions options)
        {
            Logger          = Bootstrapper.GetInstance().Container.Resolve <ILogger <DbDataReader> >(new NamedParameter("loggerName", $"EntityDataReader<{typeof(T)}>"));
            this.enumerator = col.GetEnumerator();
            this.options    = options;

            //done without a lock, so we risk running twice
            if (scalarAttributes == null)
            {
                scalarAttributes = DiscoverScalarAttributes(typeof(T));
            }
            if (options.FlattenRelatedObjects && scalarAttributesPlusRelatedObjectScalarAttributes == null)
            {
                var atts = DiscoverRelatedObjectScalarAttributes(typeof(T));
                scalarAttributesPlusRelatedObjectScalarAttributes = atts.Concat(scalarAttributes).ToList();
            }


            if (options.FlattenRelatedObjects)
            {
                attributes = scalarAttributesPlusRelatedObjectScalarAttributes;
            }
            else
            {
                attributes = scalarAttributes;
            }
        }
コード例 #2
0
        /// <summary>
        /// Enumerates the collection and copies the data into a DataTable.
        /// </summary>
        /// <typeparam name="T">The element type of the collection.</typeparam>
        /// <param name="collection">The collection to copy to a DataTable</param>
        /// <returns>A DataTable containing the scalar projection of the collection.</returns>
        public static DataTable ToDataTable <T>(this IEnumerable <T> collection)
        {
            DataTable t = new DataTable();

            t.Locale    = System.Globalization.CultureInfo.CurrentCulture;
            t.TableName = typeof(T).Name;
            EntityDataReaderOptions options = EntityDataReaderOptions.Default;

            options.ExposeNullableTypes = false;
            EntityDataReader <T> dr = new EntityDataReader <T>(collection, options);

            t.Load(dr);
            return(t);
        }
コード例 #3
0
        /// <summary>
        /// Wraps the IEnumerable in a DbDataReader, having one column for each "scalar" property of the type T.
        /// The collection will be enumerated as the client calls IDataReader.Read().
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <returns></returns>
        public static IDataReader AsEntityDataReader <T>(this IEnumerable <T> collection, bool exposeNullableColumns, bool flattenRelatedObjects)
        {
            EntityDataReaderOptions options = new EntityDataReaderOptions(exposeNullableColumns, flattenRelatedObjects, true);

            return(new EntityDataReader <T>(collection, options));
        }