Accepted answer

it sounds like you need to parameterize the property name in datacontext. one way to do it is to pass in a function that takes a datacontext and returns your enumerable (a func<datacontext, ienumerable<tsource>>) and then you would pass in a lambda like dc => dc.document as that parameter.

another option, which would work (but without type-safety) is to pass in the property's name as a string and then use reflection to access it.

public void processimportobjects<tsource, tdestination>
    (func<datacontext, ienumerable<tsource>> dcproperty,
     action<tdestination, importdatasource, int> processmethod,
     importdatasource importsource,
     int resultid)
    using (datacontext dc = new datacontext())
        dc.objecttrackingenabled = false;
        mapper.createmap<tsource, tdestination>();

        foreach (tsource d in dcproperty(dc))
            tdestination doc =<tsource, tdestination>(d);
            processmethod(doc, importsource, resultid);

Related Query

More Query from same tag