Skip to content

Configuration Conventions

markjerz edited this page Jan 8, 2016 · 1 revision

The ConfigurationBase and DefaultConfiguration classes, if you're extending them, allow you to specify an IConvention for mapping classes to tables.

string TableFor(Type entity);
string SchemaFor(Type entity);
string PrimaryKeyFor(Type entity, IEnumerable<string> propertyNames);
bool IsPrimaryKeyAutoGenerated(IColumn primaryKeyColumn);
ushort StringLengthFor(Type entity, string propertyName);
byte DecimalPrecisionFor(Type entity, string propertyName);
byte DecimalScaleFor(Type entity, string propertyName);

The default convention, cunningly named, "DefaultConvention" does the following:

TableFor

Uses the PluralizationService from System.Data.Entity.Design.PluralizationServices (with an en-GB culture) to pluralize class names.

SchemaFor

null (!!)

PrimaryKeyFor

Selects the primary key by convention from the properties. Either FooId (where Foo is the class name), Id or ID by default.

IsPrimaryKeyAutoGenerated

If it's an int, long or guid then yes, otherwise no. If set to true for a particular table it's assumed the primary key is generated on insert, in which case the primary key is fetched after insert and set on the entity.

StringLengthFor

255

DecimalPrecisionFor

18

DecimalScaleFor

10

The last 3 can be provided via the DefaultConvention constructor.

Documentation

Queries
Configuration
Tools

Clone this wiki locally