Knight Data Access Layer
Mapping By XML VB.NET
Basic Tasks VB.NET > Mapping > Mapping By XML VB.NET

When mapping with an XML file, there is no need to mark it as an embedded resource.  Simply load the XML mapping.

 

Saving and Loading XML Mappings

Dim db As IDataHelper = 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 />
    <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 />
    <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>