Click here to Skip to main content
13,297,048 members (62,784 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 5 May 2014

Map Your Sharepoint Lists in Strongly Typed Entities

, 5 May 2014
Rate this:
Please Sign up or sign in to vote.
Map your Sharepoint lists in Strongly Typed Entities


In this tip, we will learn how to convert our Sharepoint lists to Entities that are strongly typed, so it will use the Framework Sennit Sharepoint AutoMapper.

To download Sharepoint AutoMapper, please visit the project on CodePlex or the nuget.

Sennit Sharepoint Automapper

Sennit Sharepoint AutoMapper is in the initial stage, but it is possible to design ListItemCollection Entities previously configured in the future can automatically map a ListItemCollection to an Entity.

In our sources, we provide an example of usage and are working to create a good documentation for using the Framework. In this example, we use another framework ( for connection with our App Sharepoint Online in an easy way.

Create Your Entity

We will create our entity using Sharepoint Sennit AutoMapper. With it, we just need to implement IEntitySharepointMapper interface and map them utilizing some attributes of this framework.

The SharepointListName attribute maps the name of the list in SharePoint. If you do not put this attribute, it uses the entity name as the name of the list.

We also have the SharepointFieldName and IgnorePropertyInSharepoint attributes we use in this example, the first informs the property name in Sharepoint list and the second is to not try to map the attribute to the list, if not define any attributes Mapper will use the name attribute in the entity to map to the list.

Below is an example of a mapped class:

// Creating your mapped entity with Sharepoint Automapper, very easy

public class City : IEntitySharepointMapper
        [SharepointFieldName("ID")] // Name of the 
        public Int32? Id { get; set; }

        public String Name { get; set; }

        public String InternalId { get; set; }            

        public LookupFieldMapper State { get; set; }

How To Convert Your Mapped List in Entity

After we map our body can use some extensions provided by the framework that allows us to convert our entity list and vice versa.

We will show three forms of conversion using Sharepoint Mapper:

  1. ListitemCollection to the Entity List
  2. ListItemCollction for Entity
  3. Entity to ListItem

1. ListitemCollection to the Entity List

//ListItemCollection any object can send your data to a mapped entity equal to the example.

ListItemCollection listCollection;
List<City> litofCities = listCollection.ProjectToListEntity<City>();  

2. ListItemCollection for Entity

//ListItemCollection any object can send your data to a mapped entity equal to the example.

ListItemCollection listCollection;
City city = listCollection.ProjectToEntity<City>();  

3. Entity to ListItem

Web web = context.Web;

List lista = web.Lists.GetByTitle(entity.GetSharepointListName());
ListItemCreationInformation itemCreationInfo = new ListItemCreationInformation();
ListItem item = lista.AddItem(itemCreationInfo);

//Project your data from entity to ListItem, very simple :)


Lambda Expression to Caml Query

Something that is extremely difficult to be created in Sharepoint queries are queries with the framework. This task becomes extremely simple, we just need to create our query using the lambda method BuildCamlQuery that it automatically converts the lambda expression for Caml.

City city = new City(); 
string caml = city.BuildCamlQuery<Uf>(p => p.Name == "New York");   


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Carlos A Bueno
Architect Sennit
Brazil Brazil
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionAssembly generation failed -- Referenced assembly 'Sennit.SharepointAutoMapper' does not have a strong name Pin
jeff9748-Mar-15 12:49
memberjeff9748-Mar-15 12:49 
Questionis it usable just for client object model ? Pin
MBSMBS12-May-14 10:22
memberMBSMBS12-May-14 10:22 
AnswerRe: is it usable just for client object model ? Pin
Carlos A Bueno14-May-14 15:19
memberCarlos A Bueno14-May-14 15:19 
AnswerRe: is it usable just for client object model ? Pin
MBSMBS14-May-14 20:45
memberMBSMBS14-May-14 20:45 
GeneralRe: is it usable just for client object model ? Pin
jeff9746-Mar-15 5:47
memberjeff9746-Mar-15 5:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 6 May 2014
Article Copyright 2014 by Carlos A Bueno
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid