Typed list nullable db-columns

Posts   
 
    
zuma
User
Posts: 16
Joined: 18-Mar-2008
# Posted on: 09-Sep-2009 09:16:21   

Hi

When I execute the following code, it does not work:



            PoMainjournalsPlanningTypedList poMainjournals = new PoMainjournalsPlanningTypedList();

            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                IRelationPredicateBucket bucket = poMainjournals.GetRelationInfo();
                adapter.FetchTypedList(poMainjournals.GetFieldsInfo(), poMainjournals, bucket, 0, false);

                adapter.CloseConnection();
            }

Description of the Problem:

The Attribute 'PomjDealccy2Fk' is defined as "nullable" in the database. As soon as the method "adapter.FetchTypedList" is called, the following exception comes up:

ArgumentException: "The column 'PomjDealccy2Fk' cannot be set to Null. Use instead DBNull"

What did I do wrongly?

Thanks for help

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 09-Sep-2009 11:50:02   

ArgumentException: "The column 'PomjDealccy2Fk' cannot be set to Null. Use instead DBNull"

This exception must be a result of an Insert attempt. Please debug your application and see if you are inserting (saving) anything under the hood.

zuma
User
Posts: 16
Joined: 18-Mar-2008
# Posted on: 09-Sep-2009 12:41:57   

Hi

No - there is certainly no insert under the hood. I saw some threads on your forum, which had the same topic: TypedLists and problems with nullable Database-Attributes. Somehow I do not understand these threads. They tell about using methods like "IsXXXXXNull()" - but I have no control, when I call "adapter.FetchTypedList(...)". Beside of that: If I take out all nullable columns in the TypedList editor in GenPro, it works. Meaning, if I select only columns which are not nullable, it works.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 09-Sep-2009 14:14:03   

Would you please post links to these threads?

Also which LLBLGen Pro runtime library version are you using?

zuma
User
Posts: 16
Joined: 18-Mar-2008
# Posted on: 09-Sep-2009 15:48:43   

Hi

...here are the two threads, where I found a similar problem:

Thread-Id: 11395 (Title: "nullable types in typed list")

Thread-Id: 3757 (Title: "TypedList null columns")

I guess the problem is, that - when fetching the data for the typedlist - Null-Values (from a nullable attribute in the DB) are stored in the columns of the typedlist, which is not possible...it should be replaced by DBNull. But how can I do that?: When I call "adapter.FetchTypedList(...)", I have no control, until the fetch is over...and the error occurs within this Fetch-Method...

zuma
User
Posts: 16
Joined: 18-Mar-2008
# Posted on: 09-Sep-2009 15:50:52   

...here the GenPro-Version, I use...

LLBLGen Pro version: v2.6 final

.NET version: 3.5

Database type/version: Oracle 9i

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 09-Sep-2009 16:58:02   

I saw these threads, but I'm not sure if they match your issue, as they are speaking about reading a null value from the TypedView/TypedList. Which in case of a null value, they store the TypeDefaultValue, and hence no exception should be made at this stage.

Would you please post the stack trace of the above exception? Also check the following thread to know how to get the LLBLGen Pro runtime library version: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7725

zuma
User
Posts: 16
Joined: 18-Mar-2008
# Posted on: 10-Sep-2009 11:20:05   

LLBLGen Pro version + buildnr. : 2.6 final (October 6th, 200sunglasses Runtime library version : 2.6.08.1125 .NET version: 3.5 Database type/version: Oracle 9i

Code, which caused the exception:


            PoMainjournalsPlanningTypedList poMainjournals = new PoMainjournalsPlanningTypedList();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                IRelationPredicateBucket bucket = poMainjournals.GetRelationInfo();
                adapter.FetchTypedList(poMainjournals.GetFieldsInfo(), poMainjournals, bucket, 0, false);

                adapter.CloseConnection();
            }

**ArgumentException-Message: **

"Die Spalte 'PomjDealccy2Fk' kann nicht auf Null gesetzt werden. Verwenden Sie statt dessen DBNull." (german) ==> translated in english: "The column 'PomjDealccy2Fk' cannot be set to Null. Use instead DBNull"

Additional Information: The DB-Column ''PomjDealccy2Fk' is defined as 'nullable' in the database

Stacktrace

bei System.Data.DataRow.set_Item(DataColumn column, Object value)\r\n bei System.Data.DataRow.set_Item(String columnName, Object value)\r\n bei SD.LLBLGen.Pro.ORMSupportClasses.DataProjectorToDataTable.AddProjectionResultToCont ainer(IList projectors, Object[] rawProjectionResult)\r\n bei SD.LLBLGen.Pro.ORMSupportClasses.DataProjectorToDataTable.SD.LLBLGen.Pro.ORMSuppo rtClasses.IGeneralDataProjector.AddProjectionResultToContainer(List`1 valueProjectors, Object[] rawProjectionResult)\r\n bei

SD.LLBLGen.Pro.ORMSupportClasses.ProjectionUtils.FetchProjectionFromReader(List`1

valueProjectors, IGeneralDataProjector projector, IDataReader datasource, Int32 maxNumberOfItemsToReturn, Int32 pageNumber, Int32 pageSize, Boolean clientSideLimitation, Boolean clientSideDistinctFiltering, Boolean clientSidePaging, UniqueList1 stringCache, Dictionary2 typeConvertersToRun)\r\n bei SD.LLBLGen.Pro.ORMSupportClasses.DataTableFiller.Fill(IDataReader dataSource, DataTable toFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, IRetrievalQuery queryExecuted, UniqueList`1 stringCache)\r\n bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteMultiRowDataTableRe trievalQuery(IRetrievalQuery queryToExecute, DbDataAdapter dataAdapterToUse, DataTable tableToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo)\r\n bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedList(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize)\r\n bei SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchTypedList(IEntityFields2 fieldCollectionToFetch, DataTable dataTableToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, Boolean allowDuplicates)\r\n bei Midlake.DataAccess.DataAccessObjects.PoMainjournalsPlanningDao.GetPoMainjournalsPlanning(DateTime plHstructStartDate, DateTime plHstructEndDate) in C:\MIDLAKE_NET30

\midlake\DataAccess\TypedLists\PoMainjournalsPlanningDao.cs:Zeile 83

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 10-Sep-2009 11:34:04   

I checked the runtime library code and it uses DBNull.Value.

        private void AddProjectionResultToContainer( IList projectors, object[] rawProjectionResult )
        {
            if( _createColumns )
            {
                CreateColumns( projectors);
                _createColumns = false; 
            }
            // columns already exist, load per column the data from the rawProjectionResult. If a column doesn't have a propertyProjector, no data is copied.
            // if a propertyprojector isn't mentioned as a column, also no data is copied. 
            DataRow newRow = _destination.NewRow();
            for(int i=0;i<projectors.Count;i++)
            {
                if( _destination.Columns[((IProjector)projectors[i]).ProjectedResultName] != null )
                {
                    object newValue = rawProjectionResult[i];
                    if(newValue == null)
                    {
                        // Microsoft finds it unnecessary to convert null values to DBNull.Value when a cell is set to that value so we have to do that for them. 
                        newValue = DBNull.Value;
                    }
                    newRow[((IProjector)projectors[i]).ProjectedResultName] = newValue;
                }
            }
            _destination.Rows.Add(newRow);
            newRow.AcceptChanges();
        }

You are using an old runtime library version, would you please download and use the latest.