Edit 2:
Here is the code - I stripped a bit out to try to at least keep it a decent size.
private static void PollDataForObject( SF_DataPolling_Object obj )
{
try
{
using( DataClassesDataContext dc = new DataClassesDataContext( Utility.GetConnectionString() ) )
{
dc.ObjectTrackingEnabled = false;
string fields = string.Join( "," , obj.SF_DataPolling_Object_Fields.Select( x => x.FieldName ) );
string SOQL = "SELECT " + fields + " FROM " + obj.ObjectName;
if( obj.LastIntervalUpdate != null )
{
Case c = new Case();
SOQL += " WHERE CreatedDate >= " + ( ( DateTime ) obj.LastIntervalUpdate ).ToString( "yyyy'-'MM'-'dd'T'HH':'mm':'sszzzzz" ) + " OR LastModifiedDate >= " + ( ( DateTime ) obj.LastIntervalUpdate ).ToString( "yyyy'-'MM'-'dd'T'HH':'mm':'sszzzzz" );
}
QueryResult queryResult = _sfDCBinding.query( SOQL );
Type type = Type.GetType( "SF.DataPolling.Business.SFWebRef." + obj.ObjectName );
PropertyInfo[] propertiesInfo = type.GetProperties();
List<Tuple<string , object>> list = new List<Tuple<string , object>>();
string checkVal = string.Empty;
if( queryResult.size > 0 )
{
string values = string.Empty;
while( queryResult.done == false )
{
for( int i = 0 ; i < queryResult.records.Count() ; i++ )
{
// Insert the records since last interval update.
list = new List<Tuple<string , object>>();
string propertyName = string.Empty;
for( int k = 0 ; k < propertiesInfo.Count() ; k++ )
{
propertyName = propertiesInfo[ k ].Name;
if( ( from x in obj.Fields where x.FieldName == propertyName select x ).Count() > 0 )
{
object value = ( object ) propertiesInfo[ k ].GetValue( queryResult.records[ i ] , null );
list.Add( new Tuple<string , object>( propertyName , value ) );
}
}
int count = dc.spSF_CHECKIFIDEXISTS( queryResult.records[ i ].Id , config.TableDataPrefix + obj.ObjectName );
// Check if the ID exists and do update.
// If not ADD.
if( count < 1 || obj.LastIntervalUpdate == null )
{
// It's new -- insert
}
else
{
// It's an update.
//update tbl
}
}
queryResult = _sfDCBinding.queryMore( queryResult.queryLocator );
}
}
}
}
catch( Exception ex )
{
throw new Exception( ex.ToString() );
}
}