ReecordID is unique and can't be changed error

Posts   
 
    
exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 08-May-2006 16:56:52   

Hi, I have a table that has following structure

PublishedUserAlertDetailId (PK) CommentDate (PK) Comment RecordID (identity field, unique constraint)

so I try to get Comment entity populated and like this Dim comment As PublishedUserAlertDetailCommentEntity comment = PublishedUserAlertDetailCommentManager.FetchUsingUniqueConstraintRecordId( DirectCast(dgComments.DataKeys(e.Item.ItemIndex), Integer))

and I get the above error message. I cannot change the filed ReadOnly attriute in designer. Any ideas how to work around this?

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 09-May-2006 09:06:42   

Why do you need to set the Unique Key? Why do you want to remove the ReadOnly flag?

I guess you are trying to set the field somewhere in your datagrid before calling the FetchUsingUniqueConstraintRecordId method which is making the error.

If this is not the case, please post the exact error text with the complete stack trace.

Thanks

exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 09-May-2006 15:23:35   

The error happens when executing this line: comment = PublishedUserAlertDetailCommentManager.FetchUsingUniqueConstraintRecordId

What I want RecordId is to behave like surogare key, it needs to autoincrement and be unique. Maybe I don't know how to set it up in DB. I'll post the stack trace later.

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 11-May-2006 07:11:38   

waiting for the stack trace

exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 06-Sep-2006 23:05:48   

Well, I am back with a same problem and here is a stack trace

InnerException: The field 'RecordId' is read-only and can't be changed. Message: DotNetNuke.Services.Exceptions.ModuleLoadException: The field 'RecordId' is read-only and can't be changed. ---> SD.LLBLGen.Pro.ORMSupportClasses.ORMFieldIsReadonlyException: The field 'RecordId' is read-only and can't be changed. 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 MindSphere.IC.Queries.EntityClasses.UserQueryEntity.SetNewFieldValue(Int32 fieldIndex, Object value) in C:\MindSphere\INTERNAL\IC.BLL\MindSphere.IC.Queries2\Entities\EntityClasses\UserQueryEntity.vb:line 151 at MindSphere.IC.Queries.EntityClasses.UserQueryEntity.set_RecordId(Int32 Value) in C:\MindSphere\INTERNAL\IC.BLL\MindSphere.IC.Queries2\Entities\EntityClasses\UserQueryEntity.vb:line 807 at MindSphere.IC.Queries.Core.Managers.UserQueryManagerBase.FetchUsingUniqueConstraintRecordId(Int32 recordId, IDataAccessAdapter adapter) in C:\MindSphere\INTERNAL\IC.BLL\MindSphere.IC.Queries2\Core\Managers\Base\UserQueryManagerBase.vb:line 208 at MindSphere.IC.Queries.Core.Managers.UserQueryManagerBase.FetchUsingUniqueConstraintRecordId(Int32 recordId) in C:\MindSphere\INTERNAL\IC.BLL\MindSphere.IC.Queries2\Core\Managers\Base\UserQueryManagerBase.vb:line 193 at MindSphere.DNN.Modules.DataAnalyzer.QueryEdit.Page_Load(Object sender, EventArgs e) in C:\MindSphere\INTERNAL\IC_DEV\Information Center Branches\Modules\MindSphere.DataAnalyzer (shared queries)\Pages\QueryEdit.ascx.vb:line 86 --- End of inner exception stack trace ---

Problem is acutally in Manager template. Method created looks like this. RecordId is read only as it is identity column. So the question is more on manager templates. If I don't create unique constraint on this field, then templates do not generate a method, so I have to do it manually. But if I do then I have problem above. Has anybody run into this with templates?

    Public Overloads Shared Function FetchUsingUniqueConstraintRecordId( ByVal recordId As Int32, ByVal adapter As IDataAccessAdapter ) As  UserQueryEntity
            Dim entity As  New UserQueryEntity()
            
            entity.RecordId = recordId
            
            If (adapter.FetchEntityUsingUniqueConstraint(entity, entity.ConstructFilterForUCRecordId()))
                Return entity
            Else
                Return Nothing
            End If
        End Function
exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 06-Sep-2006 23:17:36   

this is probably a good solution, will have to change manager templates though

    Public Overloads Shared Function FetchUsingUniqueConstraintRecordId( ByVal recordId As Int32, ByVal adapter As IDataAccessAdapter ) As  UserQueryEntity
            Dim entity As  New UserQueryEntity()
            
            'entity.RecordId = recordId

            Dim filter As New PredicateExpression
            filter.Add(PredicateFactory.CompareValue(UserQueryFieldIndex.RecordId, ComparisonOperator.Equal, recordId))

            If (adapter.FetchEntityUsingUniqueConstraint(entity, filter)) Then
                Return entity
            Else
                Return Nothing
            End If
        End Function
Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 07-Sep-2006 06:49:41   

That's a good solution, you may also combine both ways in the same function, by checking the field.IsReadOnly flag, and if it's readOnly then you do it your way, else you use the old one.