your date filter is this:
select * from employeeaddress where effectivedate =
(select top 1 effectivedate from employeeAddress where
employeeid = @id and effectivedate <= @date
order by effectivedate desc)
and employeeid=@id
In code this is (for selfservicing, you have to add two times 'null' to the FieldCompareSetPredicate constructor for adapter, see the reference manual on FieldCompareSetPredicate constructors.
// year, month, day are today's values, I also could have just used DateTime.Now, but that would have
// the time in it of the time of call, which could miss rows inserted for today with a time later than the
// time of call.
// In-set filter.
IPredicateExpression setFilter = new PredicateExpression(
PredicateFactory.CompareValue(EmployeeAddressFieldIndex.EmployeeID, ComparisonOperator.Equal, employeeID),
PredicateExpressionOperator.And,
PredicateFactory.CompareValue(EmployeeAddressFieldIndex.EffectiveDate,
ComparisonOperator.LessEqual, new DateTime(year, month, day, 23, 59, 59)));
// compare set filter.
IPredicateExpression filter = new PredicateExpression(new FieldCompareSetPredicate(
EntityFieldFactory.Create(EmployeeAddressFieldIndex.EffectiveDate),
EntityFieldFactory.Create(EmployeeAddressFieldIndex.EffectiveDate),
SetOperator.Equal,
setFilter,
null,
string.Empty,
1,
new SortExpression(
SortClauseFactory.Create(EmployeeAddressFieldIndex.EffectiveDate, SortOperator.Descending)),
false));
You can now use filter to filter on the effective address. Of course, you then also have to filter on the specific employee also