use ordinal

This commit is contained in:
2021-11-30 18:44:06 +01:00
parent cdee9d929a
commit 2a3910a7cf

View File

@ -61,18 +61,19 @@ namespace de.hottis.genericdatabaseapiservice.Services {
Console.WriteLine("Output Property name: {0} {1} ", propertyInfo.Name, propertyInfo.PropertyType);
var attributes = propertyInfo.GetCustomAttributes(typeof(DataMemberAttribute), true);
var dma = (DataMemberAttribute)attributes[0];
Console.WriteLine("Output DataMember name: {0} {1} ", dma.Name, dma.TypeId);
int ordinal = reader.GetOrdinal(dma.Name);
Console.WriteLine("Output DataMember name: {0} {1} {2} ", dma.Name, dma.TypeId, ordinal);
if (propertyInfo.PropertyType == typeof(System.String)) {
if (reader.IsDBNull(dma.Name)) {
if (reader.IsDBNull(ordinal)) {
propertyInfo.SetValue(item, null);
Console.WriteLine("Output Value: null");
} else {
propertyInfo.SetValue(item, reader.GetString(dma.Name));
Console.WriteLine("Output Value:{0}", reader.GetString(dma.Name));
propertyInfo.SetValue(item, reader.GetString(ordinal));
Console.WriteLine("Output Value:{0}", reader.GetString(ordinal));
}
} else if (propertyInfo.PropertyType == typeof(System.Int32)) {
propertyInfo.SetValue(item, reader.GetInt32(dma.Name));
Console.WriteLine("Output Value:{0}", reader.GetInt32(dma.Name));
propertyInfo.SetValue(item, reader.GetInt32(ordinal));
Console.WriteLine("Output Value:{0}", reader.GetInt32(ordinal));
}
}
itemList.Add(item);