Export (0) Print
Expand All

EntityList<TEntity> class

Represents a Microsoft SharePoint Foundation list that can be queried with Language Integrated Query (LINQ).

System.Object
  Microsoft.SharePoint.Linq.EntityList<TEntity>

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

[PermissionSetAttribute(SecurityAction.Assert, Name = "FullTrust")]
public sealed class EntityList<TEntity> : IOrderedQueryable<TEntity>, 
	IQueryable<TEntity>, IEnumerable<TEntity>, IOrderedQueryable, IQueryable, 
	IEnumerable

Type parameters

TEntity

The content type of the list items.

This class enables querying over the list; adding, recycling, editing, or deleting list items; and registering detached objects with the change tracking system.

There is no public constructor for the class. An EntityList<TEntity> object is created with the DataContext.GetList<T>(String) method. The object returned by the ScopeToFolder(String, Boolean) method can also be cast to EntityList<TEntity>.

The following example shows how to get a reference to an EntityList<TEntity> object.

EntityList<Announcement> announcements = teamSite.GetList<Announcement>(“Announcements”)
Dim announcements As EntityList(Of Announcement) = teamSite.GetList(Of Announcement)("Announcements")

You derive a class from DataContext and declare read only EntityList<TEntity> properties in it that represent the lists of the Web site. If you do that, you can reference the lists with standard property read syntax.

The following example shows a declaration of a DataContext-derived class. Below that is an example of a query that references one of the properties without having to call GetList<T>(String).


public partial class TeamSiteDataContext : DataContext 
{
    // ctors omitted for readability.
    
    [List(Name="Projects")]
    public EntityList<Item> Projects 
    {
        get {
            return this.GetList<Item>("Projects");
        }
    }
    
    [List(Name="Managers")]
    public EntityList<Item> Managers 
    {
        get {
            return this.GetList<Item>("Managers");
        }
    }
    
    [List(Name="Team Members")]
    public EntityList<Item> TeamMembers 
    {
        get {
            return this.GetList<Item>("Team Members");
        }
    }
}

TeamSiteDataContext ourTeamSite = new TeamSiteDataContext(“http://MarketingTeam”);

var vicePresidents = from manager in ourTeamSite.Managers
                     where manager.Rank = “Vice President”
                     select manager;

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft