Knight Data Access Layer
Setting The Schema Or Owner
Basic Tasks C# > Mapping > Setting The Schema Or Owner

The schema or owner can be specified in the following ways:

 

Override the Default Schema for Auto Mapping

IDataHelper db = DataHelper.SessionFactory();

db.Mapper.DefaultSchema = "[MyDatabase].[dbo]."

 

Use the TableMappingAttribute

 

Example:

[TableMapping("Customers", "dbo.")]

public class Customer3

{

 

}

 

In code, specify the Schema property for the Table

 

IDataHelper db = DataHelper.SessionFactory();

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

table.TableName = "People";

table.Schema = "dbo.";

 

Specify with XML

 

IDataHelper db = DataHelper.SessionFactory();

db.Mapper.ObjectMap.Clear();

db.Mapper.MapTablesFromNamespace("Models");

db.Mapper.SaveObjectMap("mymap.xml");

db.Mapper.LoadObjectMap("mymap.xml");

 

Example XML Mapping

<?xml version="1.0"?>
<ArrayOfTable xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Table>
    <MappingFromDatabase>false</MappingFromDatabase>
    <Schema>dbo.</Schema>
    <ClassTypeString>KellermanSoftware.NetDataAccessLayerTests.TestClasses.SalesPeople, NET-Data-Access-Layer-Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</ClassTypeString>
    <ClassName>SalesPeople</ClassName>
    <TableName>SalesPeople</TableName>
    <Fields>
      <Field>
        <ColumnName>Salesman</ColumnName>
        <PropertyInfoString>Salesman</PropertyInfoString>
        <FieldTypeString>System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</FieldTypeString>
        <DatabaseType>AnsiString</DatabaseType>
        <Unique>false</Unique>
        <AllowDbNull>false</AllowDbNull>
        <IsPrimaryKey>false</IsPrimaryKey>
        <KeyType xsi:nil="true" />
        <IsReadOnly>false</IsReadOnly>
        <Length xsi:nil="true" />
        <IsCompositeKey>true</IsCompositeKey>
        <IsMaintenanceField>false</IsMaintenanceField>
      </Field>
      <Field>
        <ColumnName>Region</ColumnName>
        <PropertyInfoString>Region</PropertyInfoString>
        <FieldTypeString>System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</FieldTypeString>
        <DatabaseType>AnsiString</DatabaseType>
        <Unique>false</Unique>
        <AllowDbNull>false</AllowDbNull>
        <IsPrimaryKey>false</IsPrimaryKey>
        <KeyType xsi:nil="true" />
        <IsReadOnly>false</IsReadOnly>
        <Length xsi:nil="true" />
        <IsCompositeKey>true</IsCompositeKey>
        <IsMaintenanceField>false</IsMaintenanceField>
      </Field>
    </Fields>
    <CompositeKeys>
      <Field>
        <ColumnName>Salesman</ColumnName>
        <PropertyInfoString>Salesman</PropertyInfoString>
        <FieldTypeString>System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</FieldTypeString>
        <DatabaseType>AnsiString</DatabaseType>
        <Unique>false</Unique>
        <AllowDbNull>false</AllowDbNull>
        <IsPrimaryKey>false</IsPrimaryKey>
        <KeyType xsi:nil="true" />
        <IsReadOnly>false</IsReadOnly>
        <Length xsi:nil="true" />
        <IsCompositeKey>true</IsCompositeKey>
        <IsMaintenanceField>false</IsMaintenanceField>
      </Field>
      <Field>
        <ColumnName>Region</ColumnName>
        <PropertyInfoString>Region</PropertyInfoString>
        <FieldTypeString>System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</FieldTypeString>
        <DatabaseType>AnsiString</DatabaseType>
        <Unique>false</Unique>
        <AllowDbNull>false</AllowDbNull>
        <IsPrimaryKey>false</IsPrimaryKey>
        <KeyType xsi:nil="true" />
        <IsReadOnly>false</IsReadOnly>
        <Length xsi:nil="true" />
        <IsCompositeKey>true</IsCompositeKey>
        <IsMaintenanceField>false</IsMaintenanceField>
      </Field>
    </CompositeKeys>
  </Table>
  <Table>
    <MappingFromDatabase>false</MappingFromDatabase>
    <Schema>dbo.</Schema>

<ClassTypeString>KellermanSoftware.NetDataAccessLayerTests.TestClasses.Claim, NET-Data-Access-Layer-Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</ClassTypeString>
    <ClassName>Claim</ClassName>
    <TableName>Claims</TableName>
    <Fields>
      <Field>
        <ColumnName>ClaimType</ColumnName>
        <PropertyInfoString>ClaimType</PropertyInfoString>
        <FieldTypeString>System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</FieldTypeString>
        <DatabaseType>AnsiString</DatabaseType>
        <Unique>false</Unique>
        <AllowDbNull>false</AllowDbNull>
        <IsPrimaryKey>false</IsPrimaryKey>
        <KeyType xsi:nil="true" />
        <IsReadOnly>false</IsReadOnly>
        <Length xsi:nil="true" />
        <IsCompositeKey>false</IsCompositeKey>
        <IsMaintenanceField>false</IsMaintenanceField>
        <CompositionPropertyString>Detail</CompositionPropertyString>
      </Field>
    </Fields>
    <CompositeKeys />
  </Table>
</ArrayOfTable>