Class Like Mapping - Happi-cat/Untech.SharePoint GitHub Wiki

Briefly

Classes

ContextMap<TContext>

Start point of class-like mapping.

Methods:

  • ListPart<TContext> List(string listUrl) - registers site-relative Url of the desirable list and returns ListPart that should be used for list configuration.

ListPart<TContext>

Used for list configuration. New or existing instance will be returned by ContextMap<TContext>.List method.

Methods:

  • ListPart<TContext> ContentType<TEntity>([NotNull]Expression<Func<TContext, ISpList<TEntity>>> propertyAccessor, [NotNull] ContentTypeMap<TEntity> contentTypeMap) - assigns specified content type mapping to the specified property accessor.
  • ListPart<TContext> AnnotatedContentType<TEntity>([NotNull]Expression<Func<TContext, ISpList<TEntity>>> propertyAccessor) - assigns annotational mapping to the specified property accessor.

ContentTypeMap<TEntity>

This class should be used for content type mapping configuration.

Methods:

  • void ContentTypeId(string contentTypeId) - assigns content type Id of current or one of parents' content types for specified mapping.
  • FieldPart Field(Expression<Func<TEntity, object>> propertyAccessor) - registers entity member and returns FieldPart that can be used for configuration.

FieldPart

Used for field configuration. New or existing instance will be returned by ContentTypeMap<TEntity>.Field method.

Methods:

  • FieldPart InternalName(string internalName) - can be used for internal name configuration if it doesn't match with member name.
  • FieldPart TypeAsString(string typeAsString) - sets SP field type explicitly.
  • FieldPart CustomConverter<TConverter>() - associates IFieldConverter that will map from SP field to member type and vice versa.

Example

public class SmallDataContextMap : ContextMap<SmallDataContext>
{
	public SmallDataContextMap()
	{
		List("/Lists/QuickLinks")
			.ContentType(n => n.QuickLinks, new QuickLinksMap());

		List("/Lists/NavigationMenu")
			.ContentType(n => n.NavigationMenu, new NavigationMenuMap());

		// Multiple content types
		List("/Lists/News")
			.ContentType(n => n.Announcments, new AnnouncementsMap())
			.ContentType(n => n.Events, GetEventsMap());

		// Annotated content type
		List("/Lists/NavigationMenu")
			.AnnotatedContentType(n => n.Entities);
	}

	public ContentTypeMap<EventItem> GetEventsMap()
	{
		var map = new ContentTypeMap<EventItem>()

		map.Field(n => n.Title).InternalName("Title");
		map.Field(n => n.Description).InternalName("Content");
		map.Field(n => n.MeetDate);

		return map;
	}

	public class QuickLinksMap : ContentTypeMap<MenuItem>
	{
		public QuickLinksMap()
		{
			ContentTypeId("0x01");

			Field(n => n.Title).InternalName("Title");
			Field(n => n.Description).InternalName("ShortDescription");
			Field(n => n.Url).InternalName("Link").TypeAsString("Text");
		}
	}

	public class NavigationMenuMap : ContentTypeMap<MenuItem>
	{
		public NavigationMenuMap()
		{
			Field(n => n.Title).InternalName("Title");
			Field(n => n.Description).InternalName("Description");
			Field(n => n.Url).InternalName("Target").TypeAsString("Text");
		}
	}

	public class AnnouncementsMap : ContentTypeMap<AnnouncmentItem>
	{
		public AnnouncementsMap()
		{
			ContentTypeId("0x0101");

			Field(n => n.Title).InternalName("Title");
			Field(n => n.Body).InternalName("Content");
		}
	}
}
	cfgBuilder
		.RegisterMappings(n => n.ClassLike(new SmallDataContextMap()));
⚠️ **GitHub.com Fallback** ⚠️