Microsoft.SharePoint.Linq Namespace

Provides the classes that implement the LINQ to SharePoint provider.

The main gateway class that provides access to the Microsoft SharePoint Foundation is DataContext which provides for LINQ querying, writing to the content databases, and object change management. Its two most important method are GetList<T>(String), which returns the queryable EntityList<TEntity> object that represents a list, and SubmitChanges(), which writes changes to the content database.

The namespace also provides a set of “entity classes” that represent list items and field values and which, together with EntityList<TEntity> provide an object-relational mapping and interface between your object-oriented .Net code and the relational structure of the content databases. The other principal entity classes are EntityRef<TEntity>, EntitySet<TEntity>, and LookupList<T>. The first two of these implement deferred loading; so the constructor of an EntityList<TEntity> does not have to load entity objects from its entity associations. Each field in a list item is loaded only when it is first referenced in post-constructor code.

To facilitate the object-relational mapping, a rich set of attribute classes are provided. The most important of these are ContentTypeAttribute, which decorates a class that represents the content type of a list, ColumnAttribute, which decorates a property that represents a column (field) in a list, and AssociationAttribute, which decorates properties which represent a lookup relationship between a column in one list and a column in another.

LINQ to SharePoint enables writing to the content databases using optimistic concurrency. This requires a system for tracking changes to objects, detecting concurrency conflicts, and resolving those conflicts. Several classes are provided to support this system including ITrackEntityState, ObjectChangeConflict, and MemberChangeConflict.

Finally, the ICustomMapping interface provides a means of extending an already deployed SharePoint Foundation solution to handle columns added to a list after the initial deployment without requiring recompilation of the original solution assemblies or even redeployment of them.

Note

The namespace also contains two public classes needed to enable querying SharePoint Foundation lists with ADO.NET Data Services. These are not documented because they should not be called from your code.

Classes

  Class Description
Public class AssociationAttribute Specifies that the property (mapped to a list field) has an association to another list, such as when the property is mapped to a lookup field.
Public class AssociationChangedEventArgs<T> Provides data for the OnChanged event of EntityRef<TEntity>, EntitySet<TEntity>, or Microsoft.SharePoint.Linq.LookupList<T>.
Public class ChangeConflictCollection Represents a collection of ObjectChangeConflict objects.
Public class ChangeConflictException Represents the exception that is thrown when an update fails because database values have been updated since the client last read them.
Public class ChoiceAttribute Maps a member of an enumeration to a String choice value for a Choice or MultiChoice type field on a Microsoft SharePoint Foundation list.
Public class ColumnAttribute Specifies that the property is mapped to a field (column) in a Microsoft SharePoint Foundation list.
Public class ContentTypeAttribute Specifies that the class maps to a Microsoft SharePoint Foundation content type.
Public class CustomMappingAttribute Identifies what new columns are mapped with the MapFrom(Object) method that is decorated with the attribute.
Public class DataAttribute Provides two optional properties commonly used by attributes on properties (of entity classes) that are mapped to list fields (columns) or list properties.
Public class DataContext Provides LINQ (Language Integrated Query) access to, and change tracking for, the lists and document libraries of a Microsoft SharePoint Foundation Web site.
Public class DerivedEntityClassAttribute Identifies a class that derives from the class to which the attribute is applied.
Public class EntityList<TEntity> Represents a Microsoft SharePoint Foundation list that can be queried with Language Integrated Query (LINQ).
Public class EntityRef<TEntity> Provides for deferred loading and relationship maintenance for the singleton side of a one-to-many relationship.
Public class EntitySet<TEntity> Provides for deferred loading and relationship maintenance for the “many” side of one-to-many and many-to-many relationships
Public class ListAttribute Specifies that a property of a DataContext object represents a Microsoft SharePoint Foundation list.
Public class LookupList<T> Represents the values of a Microsoft SharePoint Foundation lookup field (column) that allows multiple values.
Public class MemberChangeConflict Specifies information about a discrepancy between the value of a field (or list item metadata property) in the database and its value in the current process on the front-end Web server - its client value.
Public class ObjectChangeConflict Specifies information about discrepancies between the current client value of one or more fields in a list item and the current database values of the fields.
Public class RemovedColumnAttribute Specifies that the property maps to a field (column) that is on the parent content type but was removed from the derived content type.
Public class ResourceStrings This type or member supports Microsoft Windows SharePoint Services and is not intended to be used directly from your code.
Public class Utility Provides miscellaneous functionality to the LINQ to SharePoint provider.

Interfaces

  Interface Description
Public interface ICustomMapping Enables extension of the object-relational mapping system of the LINQ to SharePoint provider.
Public interface ITrackEntityState Enables participation in the object tracking system of the LINQ to SharePoint provider.
Public interface ITrackOriginalValues Enables implementing classes to store a dictionary of changed properties and their original values.

Enumerations

  Enumeration Description
Public enumeration AssociationChangedState Specifies how an EntityRef<TEntity>, EntitySet<TEntity>, or Microsoft.SharePoint.Linq.LookupList<T> changes.
Public enumeration AssociationType Specifies the type of lookup relation between a field (column) in one list and a field in another list.
Public enumeration ConflictMode Specifies when an attempt to submit changes to a list should be stopped and a ChangeConflictException thrown.
Public enumeration EntityState Records the changed state of an entity (usually a list item; but possibly a detached entity).
Public enumeration RefreshMode Specifies how the list item changing system of the LINQ to SharePoint provider will respond when it finds that a list item has been changed by another process since it was retrieved.