miercuri, 10 martie 2010

Linq to DataSets


  • removes duplicate rows from a sequence of object
  • public static IEnumerable<TSource> Distinct<TSource>( this IEnumerable<TSource> source )
  • dataRow.Field<int>(0)
  • IEnumerable<DataRow> distinct = dt.AsEnumerable().Distinct(DataRowComparer.Default)


  • Produces the set of DataRow object difference of two sequences



  •  compares two sequence of DataRow objects to determine whether they are equal


  • Defines the extension methods to the DataRow class. This is a static class.
  • Field<T>
    • where c.Field<int>("ID") == s.Field<int>("ID")
    • Provides strongly-typed access to each of the column values in the DataRow.
    • public static T Field<T>( this DataRow row, string columnName[, DataRowVersion version] )
    • row.AcceptChanges()
      • called to make DataRow object to accept the current value for each DataColumn object within it as the original version
  • SetField<T>
    • Sets a new value for the specified column in the DataRow

DataTable Operators (System.Data.DataTableExtensions)

  •  .AsEnumerable()
    • Returns an IEnumerable<T> object, where the generic parameter T is DataRow. This object can be used in a LINQ expression or method query.
  • .CopyToDataTable<DataRow>
    • Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object.
    • System.Data.LoadOption
      • LoadOption enumeration that specifies the DataTable load options.
        • OverwriteChanges: the incoming values for this row will be written to both the current value and the original value versions of the data for each column.
        • PreserveChanges: the incoming values for this row will be written to the original value version of each column. The current version of the data in each column will not be changed. [This] is the default.
        • Upsert: The incoming values for this row will be written to the current version of each column. The original version of each column's data will not be changed.
        • DataRow.HasVersion
          • to determine if there is an original version
            • dt.AcceptChanges()


  • dataSet.Tables["Students"]
  • dataRow.Field<string>("Name")
    • or dataRow.Name in typed DataSet objects
  • studsDS.Students.AddStudentRow(1, "George");
  • studsDS.Students.where(student => student.ID == 7).Single().Name;

  • string connString = @"Data Source = .\SQLEXPRESS; InitialCatalog = Northwing; IntegrationSecurity = SSPI";
    SqlDataAdapter sda = new SqlDataAdapter("Select ... ", connString);
    DataSet ds = new DataSet();
    sda.Fill(ds, "Students");
    • Where
    • Distinct

Niciun comentariu:

Trimiteți un comentariu