/// <summary> /// Translates the System.Data.DataTable type /// to generic type objects. /// </summary> /// <typeparam name="TSource">The source type within the collection.</typeparam> /// <param name="source">The source collection array.</param> /// <returns>The array of generic type objects for the source type.</returns> /// <exception cref="System.ArgumentNullException">Source object can not be null.</exception> public static TSource[] ToArray <TSource>(this DataTable source) where TSource : class, new() { // If the source object is null. if (source == null) { throw new System.ArgumentNullException(); } Nequeo.Data.Control.AnonymousTypeFunction functions = new Nequeo.Data.Control.AnonymousTypeFunction(); // Return the data table. return(functions.Translator <TSource>(source)); }
/// <summary> /// Converts the System.Ling.IQueryable type /// to the specified type object. /// </summary> /// <typeparam name="T">The type to return.</typeparam> /// <param name="source">The current IQueryable type.</param> /// <returns>The ype array to return.</returns> public static T[] ToTypeArray <T>(this IQueryable source) where T : new() { // If the source object is null. if (source == null) { throw new System.ArgumentNullException(); } Nequeo.Data.Control.AnonymousTypeFunction functions = new Nequeo.Data.Control.AnonymousTypeFunction(); // Return the type array. return(functions.GetTypeDataArray <T>(source)); }
/// <summary> /// Get the translated foreign key reference data. /// </summary> /// <param name="property">The current property information</param> /// <param name="foreignKeyValue">The foreign key value for the referenced data entity.</param> /// <param name="data">The data column foreign key reference attribute data.</param> /// <returns>The translated data entity object.</returns> private object SetForeginKeyReferenceData(PropertyInfo property, object foreignKeyValue, Nequeo.Data.Custom.DataColumnForeignKeyAttribute data) { // Get the get method of the property. MethodInfo method = property.GetGetMethod(); string tableName = DataTypeConversion.GetSqlConversionDataType(dataContext.ProviderConnectionDataType, data.Name.TrimStart('_').Replace(".", "].[")); string colunmName = DataTypeConversion.GetSqlConversionDataType(dataContext.ProviderConnectionDataType, data.ReferenceColumnName.TrimStart('_')); DataTypeConversion dataTypeConversion = new DataTypeConversion(dataContext.ProviderConnectionDataType); // Execute the queryable provider and return the constructed // sql statement and return the data. string statement = dataTypeConversion.GetSqlStringValue(LinqTypes.GetDataType(data.ColumnType, dataContext.ProviderConnectionDataType), foreignKeyValue); DataTable table = dataContext.ExecuteQuery("SELECT * FROM " + tableName + " WHERE " + colunmName + " = " + statement); // Get the anonymous type translator from datarow // to the foreign key reference property return type. Nequeo.Data.Control.AnonymousTypeFunction typeFunction = new Nequeo.Data.Control.AnonymousTypeFunction(); return((table.Rows.Count > 0) ? typeFunction.TypeTranslator(table.Rows[0], method.ReturnType) : null); }