Entity Collection Projects and Nullable Types

Posts   
 
    
Posts: 98
Joined: 09-Feb-2005
# Posted on: 12-May-2006 22:33:39   

Hello, I'm trying to filter a typed EntityCollection<> to another EntityCollection<> of the same type. I think the filtering is working fine, but when I attempt to run the projection, I am getting the following exception:

sap.valuecollateral.tests.MetadataManagerTest.LoadMetadataCollectionByName : SD.LLBLGen.Pro.ORMSupportClasses.ORMValueTypeMismatchException : The value is of type 'System.DBNull' while the field is of type 'System.Nullable`1[System.Int32]'

The relevant portion of the stack trace:

at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ValidateValue(IEntityField2 fieldToValidate, Object value, Int32 fieldIndex) at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SetNewFieldValue(Int32 fieldIndex, Object value, Boolean fireChangeEvent) at sap.valuecollateral.dl.EntityClasses.LookupApplicationEntity.SetNewFieldValue(Int32 fieldIndex, Object value) at SD.LLBLGen.Pro.ORMSupportClasses.DataProjectorToIEntityCollection2.AddProjectionResultToContainer(IList projectors, Object[] rawProjectionResult) at SD.LLBLGen.Pro.ORMSupportClasses.DataProjectorToIEntityCollection2.SD.LLBLGen.Pro.ORMSupportClasses. IEntityDataProjector.AddProjectionResultToContainer(List1 propertyProjectors, Object[] rawProjectionResult) at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase1.CreateProjection(List1 propertyProjectors, Boolean allowDuplicates, IPredicate filter, IEntityDataProjector projector) at SD.LLBLGen.Pro.ORMSupportClasses.EntityView21.CreateProjection(List1 propertyProjectors, IEntityCollection2 destination, Boolean allowDuplicates, IPredicate filter) at SD.LLBLGen.Pro.ORMSupportClasses.EntityView21.CreateProjection(List`1 propertyProjectors, IEntityCollection2 destination)

This appears to be a problem where I have the potential for null values in the underlying table, which are being reported as DBNull and thus breaking the projection process.

Is there a suggested way around this?

Thanks all.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 13-May-2006 03:20:05   

Can you post your code that is generating the exception?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 13-May-2006 09:37:05   

Could be a bug in the entityprojector. But indeed, a code snippet is needed, also the beta build date of the designer. A few beta releases ago I've fixed a bug with null values in the projectors so I'm not sure if this is releated. Either way, it should be easy to fix.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 98
Joined: 09-Feb-2005
# Posted on: 19-May-2006 16:23:43   

Sorry Frans, As soon as I found out how to search within a collection itself, I removed the code and went with the better solution anyway. Plus, I was running an out-of-date version of the beta. I'll just close this one out. Thanks for the help all.

Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 18-Apr-2007 12:54:23   

Frans,

I have run into this (or similar) problem too...

[3664] Message: The value  is of type 'System.DBNull' while the field is of type 'System.String' 
[3664] TargetSite: Boolean ValidateValue(SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2, System.Object, Int32) 
[3664] StackTrace:  at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.ValidateValue(IEntityField2 fieldToValidate, Object value, Int32 fieldIndex) 
[3664]  at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SetNewFieldValue(Int32 fieldIndex, Object value, Boolean fireChangeEvent) 
[3664]  at Sds.ModernArk.Services.Ark.Data.EntityClasses.ItemEntity.SetNewFieldValue(Int32 fieldIndex, Object value) in C:\ModernArk\Trunk\Source\Sds.ModernArk.Services.Ark.Data\DatabaseGeneric\EntityClasses\ItemEntity.cs:line 195 
[3664]  at SD.LLBLGen.Pro.ORMSupportClasses.DataProjectorToIEntityCollection2.AddProjectionResultToContainer(IList projectors, Object[] rawProjectionResult) 
[3664]  at SD.LLBLGen.Pro.ORMSupportClasses.DataProjectorToIEntityCollection2.SD.LLBLGen.Pro.ORMSupportClasses. IGeneralDataProjector.AddProjectionResultToContainer(List`1 valueProjectors, Object[] rawProjectionResult) 
[3664]  at 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) 
[3664]  at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchProjection(List`1 valueProjectors, IGeneralDataProjector projector, IDataReader reader) 
[3664]  at Sds.ModernArk.Services.Ark.DataManagers.ItemSummaryReader.GetItemWithAdditionalInfo(Int64 itemID, Boolean includeTags, Boolean includeFolders, Boolean includeComments, Boolean includeClipboardInfo, Boolean inlcudePermissions, ReaderTools tools) in C:\ModernArk\Trunk\Source\Sds.ModernArk.Services.Ark\DataReaders\ItemSummaryReader.cs:line 373 
[3664]  at Sds.ModernArk.Services.Ark.DataManagers.ItemManager.GetItemWithAdditionalInfo(Int64 itemID, String renditionSize, Boolean includeTags, Boolean includeFolders, Boolean includeComments, Boolean includePermissions, Boolean includeLicenses, Boolean includeClipboardInfo, ReaderTools tools) in C:\ModernArk\Trunk\Source\Sds.ModernArk.Services.Ark\DataManagers\ItemManager.cs:line 290 
[3664]  at Sds.ModernArk.Services.Ark.BusinessActions.GetItemBA.DoExecute(ReaderTools tools) in C:\ModernArk\Trunk\Source\Sds.ModernArk.Services.Ark\BusinessActions\GetItemBA.cs:line 40 
[3664]  at Sds.ModernArk.Services.Ark.BusinessActions.ArkBABase.DoExecute(RequestBase request, Boolean validate) in C:\ModernArk\Trunk\Source\Sds.ModernArk.Services.Ark\BusinessActions\ArkBABase.cs:line 138 

The projector is defined as:

        private static List<IDataValueProjector> CreateItemValueProjectorList()
        {
            List<IDataValueProjector> valueProjectors = new List<IDataValueProjector>();

            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.ItemID.ToString(), 0, typeof(long)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.FileUID.ToString(), 1, typeof(Guid)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.MasterFileSystemID.ToString(), 2, typeof(short)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.MasterSubSystemID.ToString(), 3, typeof(short)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.RenditionFileSystemID.ToString(), 4, typeof(short)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.RenditionSubSystemID.ToString(), 5, typeof(short)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.OwnerAccountID.ToString(), 6, typeof(int)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.ItemTypeID.ToString(), 7, typeof(short)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.DefaultLicenseID.ToString(), 8, typeof(int)));            
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.ItemName.ToString(), 9, typeof(string)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.Description.ToString(), 10, typeof(string)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.ItemRank.ToString(), 11, typeof(string)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.ItemScore.ToString(), 12, typeof(string)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.ViewCount.ToString(), 13, typeof(int)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.CommentCount.ToString(), 14, typeof(short)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.RatingCount.ToString(), 15, typeof(short)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.RatingAverage.ToString(), 16, typeof(byte)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.ItemDate.ToString(), 17, typeof(DateTime)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.FileSize.ToString(), 18, typeof(DateTime)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.Height.ToString(), 19, typeof(int)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.Width.ToString(), 20, typeof(int)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.PrintQuality.ToString(), 21, typeof(byte)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.RenditionQuality.ToString(), 22, typeof(byte)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.RedContent.ToString(), 23, typeof(byte)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.GreenContent.ToString(), 24, typeof(byte)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.BlueContent.ToString(), 25, typeof(byte)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.Metadata.ToString(), 26, typeof(string)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.CreatedByUserID.ToString(), 27, typeof(int)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.CreatedDate.ToString(), 28, typeof(DateTime)));
            valueProjectors.Add(new DataValueProjector(ItemFieldIndex.Privacy.ToString(), 29, typeof(byte)));

            return valueProjectors;
        }

and the fetch code is


            using (IRetrievalQuery query = RetrievalProcedures.GetGetItemWithAdditionalInfoCallAsQuery(tools.UserProfile.AccountID, itemID, includeTags, includeFolders, includeComments, includeClipboardInfo))
            {
                CommandBehavior commandBehavior = adapter.KeepConnectionOpen ? CommandBehavior.Default : CommandBehavior.CloseConnection;

                using (IDataReader reader = adapter.FetchDataReader(query, commandBehavior))
                {
                    EntityCollection<ItemEntity> itemCollecion = new EntityCollection<ItemEntity>(new ItemEntityFactory());

                    DataProjectorToIEntityCollection2 projector = new DataProjectorToIEntityCollection2(itemCollecion);
                    adapter.FetchProjection(_itemValueProjectorList, projector, reader);
...

The offending field is "Metadata" which is allows NULL values (and when the field is NULL, the error occurs).

valueProjectors.Add(new DataValueProjector(ItemFieldIndex.Metadata.ToString(), 26, typeof(string)));

[edit]

Ooops. I forgot to mention that the Metadata field is of SQL type XML:

"[Metadata] [xml] NULL"

[/edit]

Im running version "2.0.0.0 Aug 3rd 2006"... this problem may have been fixed already but I could see anything about it other than this thread.

Marcus

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 18-Apr-2007 13:13:28   

This has been fixed some time ago. Could you try the latest build of the runtimes? simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 18-Apr-2007 13:17:05   

Otis wrote:

This has been fixed some time ago. Could you try the latest build of the runtimes? simple_smile

sure... I didn't see it in the change logs simple_smile - I must have missed it!

Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 18-Apr-2007 13:47:36   

Fix confirmed... upgrade solved the issue. Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 18-Apr-2007 20:39:18   

simple_smile It was fixed on September 6th:

Adapter: Projecting a datareader onto an entitycollection where DBNull values were present in the resultset caused problems in some situations.

Frans Bouma | Lead developer LLBLGen Pro