The error is:
The value is of type 'System.DBNull' while the field is of type 'System.Nullable`1[System.Int32]'
EntityCollection<UserBlogEntity> col = new EntityCollection<UserBlogEntity>(new UserBlogEntityFactory());
using (DataAccessAdapter adapter = new DataAccessAdapter(IsolationLevel.ReadUncommitted))
{
using (IRetrievalQuery query = RetrievalProcedures.GetGetTopTenUserBlogsCallAsQuery())
{
using (IDataReader reader = adapter.FetchDataReader(query, CommandBehavior.CloseConnection))
{
List<IDataValueProjector> valueProjectors = new List<IDataValueProjector>();
for (int i = 0; i < reader.FieldCount; i++)
{
string columnName = reader.GetName(i);
IEntityField2 field = EntityFieldsFactory.CreateEntityFieldsObject(EntityType.UserBlogEntity)[columnName];
valueProjectors.Add(new DataValueProjector(field.Name, i, field.DataType));
}
DataProjectorToIEntityCollection2 projector = new DataProjectorToIEntityCollection2(col);
adapter.FetchProjection(valueProjectors, projector, reader);
}
}
}
The error occurs on the final line:
adapter.FetchProjection(valueProjectors, projector, reader);
One thing to note: The structure is "Inheritance mapping" meaning that UserBlogEntity inherits from another table. However, I am specifying all columns only once and all columns are correct (i.e. they exist in the entity definition). I checked that already. It's just that there is a null value for one of the columns. That shouldn't be a problem, because LLBLGen knows the column is nullable and that's why it's a nullable type. What's going on?
It's almost as if I'm grabbing the wrong type when I pass in field.DataType
I'm trying to avoid having to specify every column manually.