I have an object DataParameterInfo (DPI) with a couple of delegate methods that are used to move data from a DataReader into a POCO or to get values out of the POCO.
Example:
new DataParameterInfo<IBulletinPCN>
{
FieldName = "ChangeProcedure",
ParameterName = "@ChangeProcedure",
EntityName = "ChangeProcedure",
DataType = SqlDbType.NVarChar,
FieldType = FieldType.Other,
PopulateEntity = (dr, e) => e.ChangeProcedure = dr.IsDBNull(dr.GetOrdinal("ChangeProcedure")) ? null : dr.GetString(dr.GetOrdinal("ChangeProcedure")),
ReadEntity = e => e.ChangeProcedure
}
I would like to refer to the Fieldname property of my DPI within the PopulateEntity delegate like such:
PopulateEntity = (dr, e) => e.ChangeProcedure = dr.IsDBNull(dr.GetOrdinal(FieldName)) ? null : dr.GetString(dr.GetOrdinal(FieldName)),
or maybe
PopulateEntity = (dr, e) => e.ChangeProcedure = dr.IsDBNull(dr.GetOrdinal(this.FieldName)) ? null : dr.GetString(dr.GetOrdinal(this.FieldName)),
Only the “this” when I try that refers to the class in which the DPI is being created, not the DPI itself.
Can I do what I’m trying, above, and if so, how?
You can pass the fieldname to your delegate as a parameter by changing the caller of that delegate:
ex:
and in the point where you execute that delegate you say: