DataContext.GetList<T> Method

Returns an object that represents the specified list and is queryable by LINQ (Language Integrated Query).

Namespace:  Microsoft.SharePoint.Linq
Assembly:  Microsoft.SharePoint.Linq (in Microsoft.SharePoint.Linq.dll)

public virtual EntityList<T> GetList<T>(
	string listName
)

Type Parameters

T

The content type of the list items.

Parameters

listName
Type: System.String

The name of the list.

Return Value

Type: Microsoft.SharePoint.Linq.EntityList<T>
An EntityList<TEntity> that represents the list.

The T parameter is defined by a class that is mapped to the list items.

NoteNote

You cannot create a second EntityList<TEntity> object with the same name and T value as one that already exists. But you can have two “Customers” lists if one has list items of type “LocalCustomer” and the other has list items of type “InternationalCustomer” You can also have two lists with the same type of list item, such as “Customer”, provided that they have different names; say “CurrentCustomers” and “InactiveCustomers.”

The following is an example of GetList<T>(String) in use. For more information on its use, see How to: Query Using LINQ to SharePoint.

EntityList<Announcement> announcements = teamSite.GetList<Announcement>(“Announcements”);
Show: