nullable
This commit is contained in:
10
DbService.cs
10
DbService.cs
@ -65,22 +65,28 @@ namespace de.hottis.genericdatabaseapiservice.Services {
|
||||
var dma = (DataMemberAttribute)attributes[0];
|
||||
int ordinal = reader.GetOrdinal(dma.Name);
|
||||
Console.WriteLine("Output DataMember name: {0} {1} {2} ", dma.Name, dma.TypeId, ordinal);
|
||||
if (reader.IsDBNull(ordinal)) {
|
||||
if (await reader.IsDBNullAsync(ordinal)) {
|
||||
propertyInfo.SetValue(item, null);
|
||||
Console.WriteLine("Output Value: null");
|
||||
} else if (propertyInfo.PropertyType == typeof(System.String)) {
|
||||
var value = reader.GetString(ordinal);
|
||||
propertyInfo.SetValue(item, value);
|
||||
Console.WriteLine("Output Value:{0}", value);
|
||||
} else if (propertyInfo.PropertyType == typeof(System.Int32)) {
|
||||
} else if (propertyInfo.PropertyType == typeof(System.Int32) ||
|
||||
propertyInfo.PropertyType == typeof(System.Nullable<System.Int32>)) {
|
||||
var value = reader.GetInt32(ordinal);
|
||||
propertyInfo.SetValue(item, value);
|
||||
Console.WriteLine("Output Value:{0}", (System.Int32)value);
|
||||
} else if (propertyInfo.PropertyType == typeof(System.DateTime)) {
|
||||
var value = reader.GetDateTime(ordinal);
|
||||
propertyInfo.SetValue(item, value);
|
||||
Console.WriteLine("Output Value:{0}", value);
|
||||
} else {
|
||||
throw new UnsupportedDataTypeException();
|
||||
}
|
||||
}
|
||||
itemList.Add(item);
|
||||
Console.WriteLine("Item is {0}", item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user