Hi,
I have searched through the forums and found how to do querys that concatenate 2 db fields into 1 result field using expressions. However i am a little stumped on how to create that single field.
One example in particular someone needed help for was:
SELECT FirstName + ' ' + LastName AS Name
FROM Employee
and a reply from Otis was:
// first grab the fields from the base class' version
IEntityFields fields = base.BuildResultset();
// now we're going to add an expression to the FullName column. this expression will
// concat the names.
Expression surNameEx = new Expression(" ", ExOp.Add, fields["Surname"]);
Expression fullNameEx = new Expression(
fields["Firstname"], ExOp.Add, surNameEx);
fields["Fullname"].ExpressionToUse = fullNameEx;
return fields;
So basically my question is, If I am creating a dynamic list, how do I initially define the field "Fullname" ?
If someone could paste a full working example, possibly based on this:
I have a Vehicle table with Manufacturer and Model. The manufacturer is a seperate lookup table. I need to use Vehicle as a lookup in this situation. So for the vehicle combo I would like to present Manufacturer.Name + " " + Vehicle.Model AS VehicleFullname. So if I could change this code into what i want, that would be excellent
public static DataTable GetVehicles(int entrantId, int seasonId)
{
// Fields
ResultsetFields fields = new ResultsetFields(3);
fields.DefineField(VehiclesFieldIndex.VehicleId, 0, "VehicleId");
fields.DefineField(ManufacturersFieldIndex.Name, 1, "Name");
fields.DefineField(VehiclesFieldIndex.Model, 2, "Model");
// Relations
RelationCollection rels = new RelationCollection();
rels.Add(VehiclesEntity.Relations.ManufacturersEntityUsingManufacturerId);
// Sorting
ISortExpression sorter = new SortExpression();
sorter.Add(SortClauseFactory.Create(ManufacturersFieldIndex.Name, SortOperator.Ascending));
sorter.Add(SortClauseFactory.Create(VehiclesFieldIndex.Model, SortOperator.Ascending));
// filtering
IPredicateExpression filtExp = new PredicateExpression();
if(entrantId != -1)
filtExp.AddWithAnd(PredicateFactory.CompareValue(VehiclesFieldIndex.EntrantId, ComparisonOperator.Equal, entrantId));
if(seasonId != -1)
filtExp.AddWithAnd(PredicateFactory.CompareValue(VehiclesFieldIndex.SeasonId, ComparisonOperator.Equal, seasonId));
TypedListDAO dao = new TypedListDAO();
DataTable Dt = new DataTable();
dao.GetMultiAsDataTable(fields, Dt, 0, sorter, filtExp, rels, true, null, null, 0, 0);
return Dt;
}
Thanks,
Matt