Search code examples
c#asp.netsql-server-2008ibatis

Ignore missing column


How can I ignore missing columns on iBatis resultMap?

If I have this mapper

<resultMap id="DBEntity" class="CS_Entity">
    <result property="Id" column="Id" />
    <result property="Field1" column="f1" />
    <result property="Field2" column="f2" />
</resultMap>

for some queries I want to return the column f2, but how can I declare without adding for all the other queries the field f2 with the default value.

There is a way?


Solution

  • Use two resultsMap one with f2

    <resultMap id="DBEntityWithF2" class="CS_Entity">
        <result property="Id" column="Id" />
        <result property="Field1" column="f1" />
        <result property="Field2" column="f2" />
    </resultMap>
    

    and another without f2

    <resultMap id="DBEntity" class="CS_Entity">
        <result property="Id" column="Id" />
        <result property="Field1" column="f1" />
    </resultMap>