The following procedure demonstrates how to create a list repository.
To create a list repository
- In Visual Studio, add a reference to the SharePoint Guidance Library Microsoft.Practices.SPG.Common.dll. If you are writing a feature receiver, item event receiver, workflow or anything else that must be in the global assembly cache, then the Microsoft.Practices.SPG.Common assembly also needs to be in the global assembly cache.
- Define a class for the business entity that corresponds to the content type fields. For information on how to create a content type and associate the content type to a list instance, see Content Types.
The following code shows an example of this step.
public class Customer
{
public string CustomerId { get; set;}
public string Name { get; set;}
public int SalesTerritoryZone { get; set; }
}
- Define a static class that contains the SharePoint field IDs for the list you want to use.
The following code shows an example of this step.
public static class CustomerFieldIds
{
public static readonly Guid IdFieldId =
new Guid("3c9699e9-2f9b-4cd6-845e-76c7e58d129a");
public static readonly Guid NameFieldId =
new Guid("84267e40-7f47-4f40-b3be-4004312eb467");
public static readonly Guid TerritoryZoneFieldId =
new Guid("7106DC30-31D9-420d-969F-24A22B7AB7CD");
}
- Define a repository class and create an instance of the ListItemFieldMapper class as a member. In the repository's constructor, add mappings that associate the field IDs of the content type to the corresponding property of the business entity. Use a string to represent the name of the business entity property. The following code shows an example.
public class CustomerRepository: ICustomerRepository
{
ListItemFieldMapper<Customer> listItemFieldMapper =
new ListItemFieldMapper<Customer>();
public CustomerRepository()
{
listItemFieldMapper.AddMapping(
CustomerFieldIds.IdFieldId,
"CustomerId");
listItemFieldMapper.AddMapping(
CustomerFieldIds.NameFieldId,
"Name");
listItemFieldMapper.AddMapping(
CustomerFieldIds.TerritoryZoneFieldId,
"SalesTerritoryZone");
}
}
Home page on MSDN | Community site