/// <summary> /// Retrieves data source information. /// </summary> /// <param name="item"></param> /// <returns></returns> internal DataSourceInfo GetDataSourceInfo(Type type) { DataSourceInfo info; if (type == null) throw new ArgumentNullException("type"); try { CacheManager mappingCache = CacheFactory.GetCacheManager(); if (mappingCache.Contains(string.Format("GetDataSourceInfo({0})", type.FullName))) return (DataSourceInfo)mappingCache[string.Format("GetDataSourceInfo({0})", type.FullName)]; Debug.WriteLine(string.Format("Getting data source information for type {0}", type.Name)); info = new DataSourceInfo(); DataSourceAttribute[] datasource = (DataSourceAttribute[])type.GetCustomAttributes(typeof(DataSourceAttribute), true); info.DataSourceName = datasource.Length > 0 ? datasource[0].Name : string.Empty; // Retrieving table name to map the object in the database. TableAttribute[] tables = (TableAttribute[])type.GetCustomAttributes(typeof(TableAttribute), true); info.DeleteCommandName = datasource.Length > 0 && !string.IsNullOrEmpty(datasource[0].DeleteCommandName) ? datasource[0].DeleteCommandName : "Delete" + (tables.Length > 0 && !string.IsNullOrEmpty(tables[0].Name) ? tables[0].Name : type.Name); info.InsertCommandName = datasource.Length > 0 && !string.IsNullOrEmpty(datasource[0].InsertCommandName) ? datasource[0].InsertCommandName : "Insert" + (tables.Length > 0 && !string.IsNullOrEmpty(tables[0].Name) ? tables[0].Name : type.Name); info.UpdateCommandName = datasource.Length > 0 && !string.IsNullOrEmpty(datasource[0].UpdateCommandName) ? datasource[0].UpdateCommandName : "Update" + (tables.Length > 0 && !string.IsNullOrEmpty(tables[0].Name) ? tables[0].Name : type.Name); info.SelectCommandName = datasource.Length > 0 && !string.IsNullOrEmpty(datasource[0].SelectCommandName) ? datasource[0].SelectCommandName : "Select" + (tables.Length > 0 && !string.IsNullOrEmpty(tables[0].Name) ? tables[0].Name : type.Name); info.DataSetAdapterName = datasource.Length > 0 && !string.IsNullOrEmpty(datasource[0].DataSetAdapterName) ? datasource[0].DataSetAdapterName : (tables.Length > 0 && !string.IsNullOrEmpty(tables[0].Name) ? tables[0].Name : type.Name) + "Adapter"; mappingCache.Add(string.Format("GetDataSourceInfo({0})", type.FullName), info, CacheItemPriority.None, null, new SlidingTime(TimeSpan.FromMinutes(15))); } catch (Exception ex) { throw ex; } return info; }
internal DataObjectHolder(object item) { _top = item; DataSet holder = new DataSet(item.GetType().Name); // Recupera la información de la fuente de datos, select command, etc. _dataSourceInfo = DataObjectManager.Current.GetDataSourceInfo(item.GetType()); // Recupera la información de la tabla, nombres de columnas, etc. _table = DataObjectManager.Current.GetObjectSchema(item.GetType()); holder.Tables.Add(_table); // enlaza los datos de la tabla al objeto. DataObjectManager.Current.GetObjectData(_table, item); }