Hi,
Sorry for the confusion. I played arround a bit with the code and ended up with the following adaptation from the code on page 447/448 of the manual.
private bool isDuplicate(int TourOpId, string TourOpCode)
{
bool result = false;
ResultsetFields fields = new ResultsetFields(2);
IRelationPredicateBucket theRPB = new RelationPredicateBucket(new FieldCompareValuePredicate(TourOperatorFields.TourOpId,null,ComparisonOperator.NotEqual,TourOpId));
IPredicateExpression theCodePredicate = new PredicateExpression(new PredicateExpression(TourOperatorFields.TourOpCode1 == TourOpCode));
theCodePredicate.AddWithOr(new PredicateExpression(TourOperatorFields.TourOpCode2 == TourOpCode));
theCodePredicate.AddWithOr(new PredicateExpression(TourOperatorFields.TourOpCode3 == TourOpCode));
theCodePredicate.AddWithOr(new PredicateExpression(TourOperatorFields.TourOpCode4 == TourOpCode));
fields.DefineField(TourOperatorFields.TourOpId, 0);
groupbyClause.Add(fields[0]);
fields.DefineField(new EntityField2("NumberOfCodes", new ScalarQueryExpression(TourOperatorFields.TourOpId.SetAggregateFunction(AggregateFunction.Count),
theCodePredicate, null,null)), 1);
DataTable resultsTable = new DataTable();
using (IDataAccessAdapter da = new DataAccessAdapter())
{
da.FetchTypedList(fields, resultsTable, theRPB);
result = (resultsTable.Rows.Count > 0);
}
return result;
}
I didn't get the results I wanted and gave up using LLBLGen due to time constraints. I ended up using plain SQL to get the result I wanted. Here's the code.
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["CaptureV4.ConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("SELECT count(*) FROM (select tour_op_id FROM Tour_operator where tour_op_code1 = @TCODE or tour_op_code2 = @TCODE or tour_op_code3 = @TCODE or tour_op_code4 = @TCODE) as c where c.tour_op_id <> @TID", cn);
cmd.Parameters.AddWithValue("@TCODE", TourOpCode);
cmd.Parameters.AddWithValue("@TID", TourOpId);
cn.Open();
Int32 count = (Int32)cmd.ExecuteScalar();
return (count > 0);
The purpose of this code was to find the number of IDs that had the same code as the selected ID. I would like to understand how to get this query into LLBLGen objects but at the moment I don't have a great deal of time to experiment on this.
Regards
Michael Mason