Knight Data Access Layer
Mapping By Code
Basic Tasks C# > Mapping > Mapping By Code

Mappings can be entirely created in code.  Mappings can be created from scratch or mappings can be augmented by generating the mapping first.

 

Manual Mapping

IDataHelper db = DataHelper.SessionFactory();

Table table = new Table(typeof(Person));

table.TableName = "People";

Field field = new Field(table, "FirstName", "FirstName");

table.Fields.Add(field);

db.Mapper.ObjectMap.Add(typeof(Person),table);

 

Partially Automatic Mapping

IDataHelper db = DataHelper.SessionFactory();

Table table = _db.Mapper.GetObjectMap(typeof(Customer));

table.Fields.First(o => o.PropertyInfoString == "Name").DatabaseType = DbType.String;