Пример #1
0
        /// <summary>
        /// DataReader到Collection
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <param name="dr"></param>
        /// <param name="items"></param>
        /// <param name="dod"></param>
        /// <returns>返回原有的集合</returns>
        public static EditableDataObjectCollectionBase <T> DataReaderToCollection <T>(EditableDataObjectCollectionBase <T> collection, IDataReader dr, ORMappingItemCollection items, DataToObjectDeligations dod) where T : new()
        {
            dr.NullCheck("dr");
            items.NullCheck("items");
            dod.NullCheck("dod");

            using (ORMappingContext context = ORMappingContext.GetContext())
            {
                while (dr.Read())
                {
                    collection.Add(DataReaderToObject(dr, items, new T(), dod));
                }
            }

            return(collection);
        }
Пример #2
0
        /// <summary>
        /// DataView的数据转换到集合中
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <param name="items"></param>
        /// <param name="view"></param>
        /// <param name="dod"></param>
        /// <returns>返回原有的集合</returns>
        public static EditableDataObjectCollectionBase <T> DataViewToCollection <T>(EditableDataObjectCollectionBase <T> collection, ORMappingItemCollection items, DataView view, DataToObjectDeligations dod) where T : new()
        {
            collection.NullCheck("collection");
            items.NullCheck("items");
            view.NullCheck("view");

            using (ORMappingContext context = ORMappingContext.GetContext())
            {
                foreach (DataRowView drv in view)
                {
                    collection.Add(DataRowToObject(drv.Row, items, new T(), dod));
                }
            }

            return(collection);
        }
Пример #3
0
        /// <summary>
        /// DataReader到Collection
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <param name="dr"></param>
        /// <param name="items"></param>
        /// <param name="dod"></param>
        public static void DataReaderToCollection <T>(EditableDataObjectCollectionBase <T> collection, IDataReader dr, ORMappingItemCollection items, DataToObjectDeligations dod) where T : new()
        {
            dr.NullCheck("dr");
            items.NullCheck("items");
            dod.NullCheck("dod");

            using (ORMappingContext context = ORMappingContext.GetContext())
            {
                while (dr.Read())
                {
                    T graph = new T();

                    DataReaderToObject(dr, items, graph, dod);

                    collection.Add(graph);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// 根据映射关系,得到Select语句中返回的字段名称数组
        /// </summary>
        /// <param name="mapping"></param>
        /// <param name="ignoreProperties"></param>
        /// <returns></returns>
        public static string[] GetSelectFieldsName(ORMappingItemCollection mapping, params string[] ignoreProperties)
        {
            mapping.NullCheck("mapping");
            ignoreProperties.NullCheck("ignoreProperties");

            List <string> result = new List <string>();

            foreach (ORMappingItem item in mapping)
            {
                if ((item.BindingFlags & ClauseBindingFlags.Select) != ClauseBindingFlags.None)
                {
                    if (Array.Exists <string>(ignoreProperties, target => (string.Compare(target, item.PropertyName, true) == 0)
                                              ) == false)
                    {
                        result.Add(item.DataFieldName);
                    }
                }
            }

            return(result.ToArray());
        }