Result Set and Parameter Extension Methods

The following extension methods are used with the result sets of the query extension methods or the parameters passed to them. See the extension method documentation for usage examples.

Result Set Extension Methods

The following result set extension methods are available:

  • ToTrackingBindingListTEntity - This converts an enumerable list of change tracking entities to a binding list that will notify the related data context of additions, changes, and deletions. The returned binding list is only suitable for binding to Windows Forms controls. Use the method below for WPF controls.

  • ToTrackingCollectionTEntity - This converts an enumerable list of change tracking entities to an observable collection that will notify the related data context of additions, changes, and deletions. The returned observable collection is only suitable for use with WPF controls. Use the method above for Windows Forms controls.

Parameter Value Extension Methods

The following parameter value extension methods are available:

  • NullIfEmpty - This is used to convert strings to null values if they are empty. This is useful for passing string values to database context methods when the value needs to be passed or stored as a null value rather than an empty string.

  • NullIfWhiteSpace - This is used to convert strings to null values if they are empty or all whitespace. This is useful for passing string values to database context methods when the value needs to be passed or stored as a null value rather than an empty or whitespace string.

  • ToStringOrNull - This is used to convert an object to a string and return either the string value if not empty, or null if it is an empty string. This is useful for passing object values to database context methods when the value needs to be passed or stored as a null value rather than an empty string.

  • ToChar - This is used to convert a string value to a nullable Char by returning null if the string is null or empty or the first character of the string if not.

  • ToNullable - This is used to convert value types to null values if they are set to their default value for the type (i.e. zero for integers, DateTime.MinValue for date/times, etc). This is useful for passing values to database context methods when the parameters needs to be passed or stored as a null value rather than a literal value if it is set to the default.

  • ToNullable - This is used to convert objects to null values if they are equal to null, DBNull.Value, or the default value for the given type. This is useful for passing values to database context methods when the parameters needs to be passed or stored as a null rather than DBNull.Value or the type's default value.

See Also

Other Resources