Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Auto mapping generic base classes

n074v41l4bl34u edited this page Sep 7, 2014 · 1 revision

It's common to extract properties common to all (or most) of your entities into a base-class. Sometimes you may want your base-class to be an open generic type, with which each inheritor can change the generic argument for different behaviour.

An example of this is using a single generic argument to dictate the Id type.

public abstract class BaseEntity<T>  
{  
  public T Id { get; private set; }  
}

When using this kind of base-class, you just need to ignore it like any other base type.

AutoMap.AssemblyOf<Entity>()
  .IgnoreBase(typeof(BaseEntity<>));

You just need to remember to use the unbound type definition for it to apply to all subclasses (BaseEntity<> instead of BaseEntity<int>).

Clone this wiki locally
Morty Proxy This is a proxified and sanitized view of the page, visit original site.