Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add DataTableExtensions.AsDataView #36528

Merged
merged 9 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/Microsoft.Private.PackageBaseline/packageIndex.json
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,9 @@
],
"BaselineVersion": "4.5.0",
"InboxOn": {
"net45": "4.0.0.0"
"net45": "4.0.0.0",
"netcoreapp3.0": "4.0.0.0",
"uap10.0.16300": "4.0.0.0"
},
"AssemblyVersionInPackageVersion": {
"4.0.0.0": "4.6.0"
Expand Down
80 changes: 80 additions & 0 deletions src/System.Data.Common/ref/System.Data.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,29 @@ public void InsertAt(System.Data.DataRow row, int pos) { }
public void Remove(System.Data.DataRow row) { }
public void RemoveAt(int index) { }
}
public static partial class DataRowComparer
{
public static System.Data.DataRowComparer<System.Data.DataRow> Default { get { throw null; } }
}
public sealed partial class DataRowComparer<TRow> : System.Collections.Generic.IEqualityComparer<TRow> where TRow : System.Data.DataRow
{
internal DataRowComparer() { }
public static System.Data.DataRowComparer<TRow> Default { get { throw null; } }
public bool Equals(TRow leftRow, TRow rightRow) { throw null; }
public int GetHashCode(TRow row) { throw null; }
}
public static partial class DataRowExtensions
{
public static T Field<T>(this System.Data.DataRow row, System.Data.DataColumn column) { throw null; }
public static T Field<T>(this System.Data.DataRow row, System.Data.DataColumn column, System.Data.DataRowVersion version) { throw null; }
public static T Field<T>(this System.Data.DataRow row, int columnIndex) { throw null; }
public static T Field<T>(this System.Data.DataRow row, int columnIndex, System.Data.DataRowVersion version) { throw null; }
public static T Field<T>(this System.Data.DataRow row, string columnName) { throw null; }
public static T Field<T>(this System.Data.DataRow row, string columnName, System.Data.DataRowVersion version) { throw null; }
public static void SetField<T>(this System.Data.DataRow row, System.Data.DataColumn column, T value) { }
public static void SetField<T>(this System.Data.DataRow row, int columnIndex, T value) { }
public static void SetField<T>(this System.Data.DataRow row, string columnName, T value) { }
}
[System.FlagsAttribute]
public enum DataRowState
{
Expand Down Expand Up @@ -757,6 +780,15 @@ public void Remove(string name) { }
public void Remove(string name, string tableNamespace) { }
public void RemoveAt(int index) { }
}
public static partial class DataTableExtensions
{
public static System.Data.DataView AsDataView(this System.Data.DataTable table) { throw null; }
public static System.Data.DataView AsDataView<T>(this System.Data.EnumerableRowCollection<T> source) where T : System.Data.DataRow { throw null; }
public static System.Data.EnumerableRowCollection<System.Data.DataRow> AsEnumerable(this System.Data.DataTable source) { throw null; }
public static System.Data.DataTable CopyToDataTable<T>(this System.Collections.Generic.IEnumerable<T> source) where T : System.Data.DataRow { throw null; }
public static void CopyToDataTable<T>(this System.Collections.Generic.IEnumerable<T> source, System.Data.DataTable table, System.Data.LoadOption options) where T : System.Data.DataRow { }
public static void CopyToDataTable<T>(this System.Collections.Generic.IEnumerable<T> source, System.Data.DataTable table, System.Data.LoadOption options, System.Data.FillErrorEventHandler errorHandler) where T : System.Data.DataRow { }
}
public sealed partial class DataTableNewRowEventArgs : System.EventArgs
{
public DataTableNewRowEventArgs(System.Data.DataRow dataRow) { }
Expand Down Expand Up @@ -1046,6 +1078,31 @@ protected DuplicateNameException(System.Runtime.Serialization.SerializationInfo
public DuplicateNameException(string s) { }
public DuplicateNameException(string message, System.Exception innerException) { }
}
public abstract partial class EnumerableRowCollection : System.Collections.IEnumerable
{
internal EnumerableRowCollection() { }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
}
public static partial class EnumerableRowCollectionExtensions
{
public static System.Data.EnumerableRowCollection<TResult> Cast<TResult>(this System.Data.EnumerableRowCollection source) { throw null; }
public static System.Data.OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey>(this System.Data.EnumerableRowCollection<TRow> source, System.Func<TRow, TKey> keySelector) { throw null; }
public static System.Data.OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey>(this System.Data.EnumerableRowCollection<TRow> source, System.Func<TRow, TKey> keySelector, System.Collections.Generic.IComparer<TKey> comparer) { throw null; }
public static System.Data.OrderedEnumerableRowCollection<TRow> OrderBy<TRow, TKey>(this System.Data.EnumerableRowCollection<TRow> source, System.Func<TRow, TKey> keySelector) { throw null; }
public static System.Data.OrderedEnumerableRowCollection<TRow> OrderBy<TRow, TKey>(this System.Data.EnumerableRowCollection<TRow> source, System.Func<TRow, TKey> keySelector, System.Collections.Generic.IComparer<TKey> comparer) { throw null; }
public static System.Data.EnumerableRowCollection<S> Select<TRow, S>(this System.Data.EnumerableRowCollection<TRow> source, System.Func<TRow, S> selector) { throw null; }
public static System.Data.OrderedEnumerableRowCollection<TRow> ThenByDescending<TRow, TKey>(this System.Data.OrderedEnumerableRowCollection<TRow> source, System.Func<TRow, TKey> keySelector) { throw null; }
public static System.Data.OrderedEnumerableRowCollection<TRow> ThenByDescending<TRow, TKey>(this System.Data.OrderedEnumerableRowCollection<TRow> source, System.Func<TRow, TKey> keySelector, System.Collections.Generic.IComparer<TKey> comparer) { throw null; }
public static System.Data.OrderedEnumerableRowCollection<TRow> ThenBy<TRow, TKey>(this System.Data.OrderedEnumerableRowCollection<TRow> source, System.Func<TRow, TKey> keySelector) { throw null; }
public static System.Data.OrderedEnumerableRowCollection<TRow> ThenBy<TRow, TKey>(this System.Data.OrderedEnumerableRowCollection<TRow> source, System.Func<TRow, TKey> keySelector, System.Collections.Generic.IComparer<TKey> comparer) { throw null; }
public static System.Data.EnumerableRowCollection<TRow> Where<TRow>(this System.Data.EnumerableRowCollection<TRow> source, System.Func<TRow, bool> predicate) { throw null; }
}
public partial class EnumerableRowCollection<TRow> : System.Data.EnumerableRowCollection, System.Collections.Generic.IEnumerable<TRow>, System.Collections.IEnumerable
{
internal EnumerableRowCollection() { }
public System.Collections.Generic.IEnumerator<TRow> GetEnumerator() { throw null; }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
}
public partial class EvaluateException : System.Data.InvalidExpressionException
{
public EvaluateException() { }
Expand Down Expand Up @@ -1332,6 +1389,10 @@ protected NoNullAllowedException(System.Runtime.Serialization.SerializationInfo
public NoNullAllowedException(string s) { }
public NoNullAllowedException(string message, System.Exception innerException) { }
}
public sealed partial class OrderedEnumerableRowCollection<TRow> : System.Data.EnumerableRowCollection<TRow>
{
internal OrderedEnumerableRowCollection() { }
}
public enum ParameterDirection
{
Input = 1,
Expand Down Expand Up @@ -1450,6 +1511,25 @@ protected SyntaxErrorException(System.Runtime.Serialization.SerializationInfo in
public SyntaxErrorException(string s) { }
public SyntaxErrorException(string message, System.Exception innerException) { }
}
public static partial class TypedTableBaseExtensions
{
public static System.Data.EnumerableRowCollection<TRow> AsEnumerable<TRow>(this System.Data.TypedTableBase<TRow> source) where TRow : System.Data.DataRow { throw null; }
public static TRow ElementAtOrDefault<TRow>(this System.Data.TypedTableBase<TRow> source, int index) where TRow : System.Data.DataRow { throw null; }
public static System.Data.OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey>(this System.Data.TypedTableBase<TRow> source, System.Func<TRow, TKey> keySelector) where TRow : System.Data.DataRow { throw null; }
public static System.Data.OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey>(this System.Data.TypedTableBase<TRow> source, System.Func<TRow, TKey> keySelector, System.Collections.Generic.IComparer<TKey> comparer) where TRow : System.Data.DataRow { throw null; }
public static System.Data.OrderedEnumerableRowCollection<TRow> OrderBy<TRow, TKey>(this System.Data.TypedTableBase<TRow> source, System.Func<TRow, TKey> keySelector) where TRow : System.Data.DataRow { throw null; }
public static System.Data.OrderedEnumerableRowCollection<TRow> OrderBy<TRow, TKey>(this System.Data.TypedTableBase<TRow> source, System.Func<TRow, TKey> keySelector, System.Collections.Generic.IComparer<TKey> comparer) where TRow : System.Data.DataRow { throw null; }
public static System.Data.EnumerableRowCollection<S> Select<TRow, S>(this System.Data.TypedTableBase<TRow> source, System.Func<TRow, S> selector) where TRow : System.Data.DataRow { throw null; }
public static System.Data.EnumerableRowCollection<TRow> Where<TRow>(this System.Data.TypedTableBase<TRow> source, System.Func<TRow, bool> predicate) where TRow : System.Data.DataRow { throw null; }
}
public abstract partial class TypedTableBase<T> : System.Data.DataTable, System.Collections.Generic.IEnumerable<T>, System.Collections.IEnumerable where T : System.Data.DataRow
{
protected TypedTableBase() { }
protected TypedTableBase(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public System.Data.EnumerableRowCollection<TResult> Cast<TResult>() { throw null; }
public System.Collections.Generic.IEnumerator<T> GetEnumerator() { throw null; }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
}
[System.ComponentModel.DefaultPropertyAttribute("ConstraintName")]
public partial class UniqueConstraint : System.Data.Constraint
{
Expand Down
10 changes: 10 additions & 0 deletions src/System.Data.Common/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,14 @@
<data name="ADP_DbProviderFactories_FactoryNotLoadable" xml:space="preserve"><value>The registered .NET Data Provider's DbProviderFactory implementation type '{0}' couldn't be loaded.</value></data>
<data name="ADP_DbProviderFactories_NoAssemblyQualifiedName" xml:space="preserve"><value>The missing .NET Data Provider's assembly qualified name is required.</value></data>
<data name="ADP_DbProviderFactories_NotAFactoryType" xml:space="preserve"><value>The type '{0}' doesn't inherit from DbProviderFactory.</value></data>
<data name="DataSetLinq_InvalidEnumerationValue" xml:space="preserve"><value>The {0} enumeration value, {1}, is not valid.</value></data>
<data name="LDV_InvalidNumOfKeys" xml:space="preserve"><value>Must provide '{0}' keys to find.</value></data>
<data name="LDVRowStateError" xml:space="preserve"><value>DataViewRowState must be DataViewRowState.CurrentRows.</value></data>
<data name="ToLDVUnsupported" xml:space="preserve"><value>Can not create DataView after using projection.</value></data>
<data name="DataSetLinq_EmptyDataRowSource" xml:space="preserve"><value>The source contains no DataRows.</value></data>
<data name="DataSetLinq_NullDataRow" xml:space="preserve"><value>The source contains a DataRow reference that is null.</value></data>
<data name="DataSetLinq_CannotLoadDetachedRow" xml:space="preserve"><value>The source contains a detached DataRow that cannot be copied to the DataTable.</value></data>
<data name="DataSetLinq_CannotCompareDeletedRow" xml:space="preserve"><value>The DataRowComparer does not work with DataRows that have been deleted since it only compares current values.</value></data>
<data name="DataSetLinq_CannotLoadDeletedRow" xml:space="preserve"><value>The source contains a deleted DataRow that cannot be copied to the DataTable.</value></data>
<data name="DataSetLinq_NonNullableCast" xml:space="preserve"><value>Cannot cast DBNull. Value to type '{0}'. Please use a nullable type.</value></data>
</root>
11 changes: 11 additions & 0 deletions src/System.Data.Common/src/System.Data.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,23 @@
<Compile Include="System\Data\DataRowChangeEvent.cs" />
<Compile Include="System\Data\DataRowChangeEventHandler.cs" />
<Compile Include="System\Data\DataRowCollection.cs" />
<Compile Include="System\Data\DataRowComparer.cs" />
<Compile Include="System\Data\DataRowCreatedEventHandler.cs" />
<Compile Include="System\Data\DataRowExtensions.cs" />
<Compile Include="System\Data\DataRowState.cs" />
<Compile Include="System\Data\DataRowVersion.cs" />
<Compile Include="System\Data\DataRowView.cs" />
<Compile Include="System\Data\DataSerializationFormat.cs" />
<Compile Include="System\Data\DataSet.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="System\Data\DataSetUtil.cs" />
<Compile Include="System\Data\DataSetDateTime.cs" />
<Compile Include="System\Data\DataSysAttribute.cs" />
<Compile Include="System\Data\DataTable.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="System\Data\DataTableExtensions.cs" />
<Compile Include="System\Data\DataTableClearEvent.cs" />
<Compile Include="System\Data\DataTableClearEventHandler.cs" />
<Compile Include="System\Data\DataTableCollection.cs" />
Expand All @@ -99,6 +103,8 @@
<Compile Include="System\Data\DBConcurrencyException.cs" />
<Compile Include="System\Data\DbType.cs" />
<Compile Include="System\Data\DefaultValueTypeConverter.cs" />
<Compile Include="System\Data\EnumerableRowCollection.cs" />
<Compile Include="System\Data\EnumerableRowCollectionExtensions.cs" />
<Compile Include="System\Data\FillErrorEventArgs.cs" />
<Compile Include="System\Data\FillErrorEventHandler.cs" />
<Compile Include="System\Data\ForeignKeyConstraint.cs" />
Expand All @@ -118,13 +124,15 @@
<Compile Include="System\Data\ITableMapping.cs" />
<Compile Include="System\Data\ITableMappingCollection.cs" />
<Compile Include="System\Data\KeyRestrictionBehavior.cs" />
<Compile Include="System\Data\LinqDataView.cs" />
<Compile Include="System\Data\LoadOption.cs" />
<Compile Include="System\Data\MappingType.cs" />
<Compile Include="System\Data\MergeFailedEvent.cs" />
<Compile Include="System\Data\MergeFailedEventHandler.cs" />
<Compile Include="System\Data\Merger.cs" />
<Compile Include="System\Data\MissingMappingAction.cs" />
<Compile Include="System\Data\MissingSchemaAction.cs" />
<Compile Include="System\Data\OrderedEnumerableRowCollection.cs" />
<Compile Include="System\Data\ParameterDirection.cs" />
<Compile Include="System\Data\PrimaryKeyTypeConverter.cs" />
<Compile Include="System\Data\PropertyCollection.cs" />
Expand All @@ -143,11 +151,14 @@
<Compile Include="System\Data\Select.cs" />
<Compile Include="System\Data\Selection.cs" />
<Compile Include="System\Data\SimpleType.cs" />
<Compile Include="System\Data\SortExpressionBuilder.cs" />
<Compile Include="System\Data\SqlDbType.cs" />
<Compile Include="System\Data\StateChangeEvent.cs" />
<Compile Include="System\Data\StateChangeEventHandler.cs" />
<Compile Include="System\Data\StatementType.cs" />
<Compile Include="System\Data\StrongTypingException.cs" />
<Compile Include="System\Data\TypedTableBase.cs" />
<Compile Include="System\Data\TypedTableBaseExtensions.cs" />
<Compile Include="System\Data\UniqueConstraint.cs" />
<Compile Include="System\Data\UpdateRowSource.cs" />
<Compile Include="System\Data\Common\UInt64Storage.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,8 @@ public int GetHashCode(TRow row)
}
else
{
ValueType vt = value as ValueType;

// have to unbox value types.
if (vt != null)
if (value is ValueType vt)
{
hash = vt.GetHashCode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace System.Data
/// <summary>
/// This static class defines the DataTable extension methods.
/// </summary>
public static class DataTableExtensions
public static partial class DataTableExtensions
{
/// <summary>
/// This method returns a IEnumerable of Datarows.
Expand Down Expand Up @@ -218,5 +218,28 @@ private static DataTable LoadTableFromEnumerable<T>(IEnumerable<T> source, DataT
Debug.Assert(null != table, "null DataTable");
return table;
}

/// <summary>
/// Creates a LinkDataView of DataRow over the input table.
/// </summary>
/// <param name="table">DataTable that the view is over.</param>
/// <returns>An instance of LinkDataView.</returns>
public static DataView AsDataView(this DataTable table)
{
DataSetUtil.CheckArgumentNull<DataTable>(table, nameof(table));
return new LinqDataView(table, null);
}

/// <summary>
/// Creates a LinqDataView from EnumerableDataTable
/// </summary>
/// <typeparam name="T">Type of the row in the table. Must inherit from DataRow</typeparam>
/// <param name="source">The enumerable-datatable over which view must be created.</param>
/// <returns>Generated LinkDataView of type T</returns>
public static DataView AsDataView<T>(this EnumerableRowCollection<T> source) where T : DataRow
{
DataSetUtil.CheckArgumentNull<EnumerableRowCollection<T>>(source, nameof(source));
return source.GetLinqDataView();
}
}
}
36 changes: 36 additions & 0 deletions src/System.Data.Common/src/System/Data/DataView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,36 @@ public DataView(DataTable table, string RowFilter, string Sort, DataViewRowState
SetIndex(Sort, RowState, newFilter);
}

internal DataView(DataTable table, System.Predicate<DataRow> predicate, System.Comparison<DataRow> comparison, DataViewRowState RowState)
{
GC.SuppressFinalize(this);
DataCommonEventSource.Log.Trace("<ds.DataView.DataView|API> %d#, table=%d, RowState=%d{ds.DataViewRowState}\n",
ObjectID, (table != null) ? table.ObjectID : 0, (int)RowState);

if (table == null)
{
throw ExceptionBuilder.CanNotUse();
}

_dvListener = new DataViewListener(this);
_locked = false;
_table = table;
_dvListener.RegisterMetaDataEvents(table);

if ((((int)RowState) & ((int)~(DataViewRowState.CurrentRows | DataViewRowState.OriginalRows))) != 0)
{
throw ExceptionBuilder.RecordStateRange();
}
else if ((((int)RowState) & ((int)DataViewRowState.ModifiedOriginal)) != 0 &&
(((int)RowState) & ((int)DataViewRowState.ModifiedCurrent)) != 0)
{
throw ExceptionBuilder.SetRowStateFilter();
}

_comparison = comparison;
SetIndex2("", RowState, ((null != predicate) ? new RowPredicateFilter(predicate) : null), true);
}

/// <summary>
/// Sets or gets a value indicating whether deletes are allowed.
/// </summary>
Expand Down Expand Up @@ -726,6 +756,12 @@ internal virtual DataRowView[] FindRowsByKey(object[] key)
}
}

/// <summary>This method exists for LinqDataView to keep a level of abstraction away from the RBTree</summary>
internal Range FindRecords<TKey,TRow>(Index.ComparisonBySelector<TKey,TRow> comparison, TKey key) where TRow:DataRow
{
return _index.FindRecords(comparison, key);
}

/// <summary>Convert a Range into a DataRowView[].</summary>
internal DataRowView[] GetDataRowViewFromRange(Range range)
{
Expand Down
Loading