예제 #1
0
        /// <summary>
        /// LINQ's Where operator for generic EnumerableRowCollection.
        /// </summary>
        public static EnumerableRowCollection <TRow> Where <TRow>(this TypedTableBase <TRow> source, Func <TRow, bool> predicate) where TRow : DataRow
        {
            DataSetUtil.CheckArgumentNull(nameof(source), "source");
            EnumerableRowCollection <TRow> erc = new EnumerableRowCollection <TRow>(source);

            return(erc.Where(predicate));
        }
        public void Where_SuccessfullyFindRow()
        {
            TypedTableBase <DataRow> table = new TestTypedTable <DataRow>();

            table.Columns.Add();
            DataRow two = table.Rows.Add("two");

            EnumerableRowCollection <DataRow> source = table.Cast <DataRow>();

            var filtered = source.Where(row => "two".Equals(row.ItemArray[0]));

            // Check that only one row matches predicate condition
            Assert.Equal(1, filtered.Count());

            // Check that matching row is the same object as the second data row
            Assert.Same(two, filtered.First());
        }