Hello all,
I am trying to create a concatenated group of fields to use in a DropDownList as the DataTextField and discovered a way to deal with different data types. Previously, I was getting SqlClient exceptions because there are several different types, namely nvarchar, datetime and bigint.
The exception was System.Data.SqlClient.SqlException: Error converting data type nvarchar to bigint.
I solved it with the following, after trying both ExpressionToApply and defining a new EntityField:
fields.DefineField(CustomerFields.CustomerId, 0);
fields.DefineField(CustomerFields.Name, 1, "CustomerDataTextField");
fields[1].ExpressionToApply = new DbFunctionCall("{0} + ', ' + CONVERT(nvarchar(255), {1})", new object[] { fields[1], fields[0] });
This yields Name + CustomerId in the CustomerDataTextField column in the DataTable.
Hope this is helpful, and of course alternate ways of doing the same are welcome.