Projection error with nullable types.

Posts   
 
    
ncook
User
Posts: 7
Joined: 20-Sep-2006
# Posted on: 20-Sep-2006 00:27:01   

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.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 20-Sep-2006 04:53:02   

For the null value is the field marked to (.NET 2.0)Generate as Nullable Type in the designer?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Sep-2006 09:49:48   

This is a bug which is fixed in a recent build of the runtimes. Could you please upgrade to the latest runtimes?

Frans Bouma | Lead developer LLBLGen Pro
ncook
User
Posts: 7
Joined: 20-Sep-2006
# Posted on: 20-Sep-2006 15:19:15   

Thank you for your replies! I will check both things and report back if I continue to have problems.

ncook
User
Posts: 7
Joined: 20-Sep-2006
# Posted on: 20-Sep-2006 21:24:38   

That fixed it.

Just wanted to say thanks!

Nate