Delete PersonInORG Script

Hello I want to delete the assignments to PersonInOrg. Unfortunately that doesn't work and I don't get a meaningful error. Do I have to do a deep delete?

'Remove all Assigments to all Project Rolls for the user
'==================================================

'Loop throu all sub Project Rols
For Each colbRoleElement As IEntity In colbRole
	Dim colbeAssigments As IEntityCollection
	Dim fRoleAssigments As ISqlFormatter = Session.SqlFormatter
	'Query is there an Assigments to Role and Userid
	Dim qRoleAssigments = Query.From("PersonInORG") _
              .Where(fRoleAssigments.AndRelation(fRoleAssigments.Comparison("UID_ORG", colbRoleElement.GetValue("UID_Org").String, ValType.String, CompareOperator.Equal),fRoleAssigments.Comparison("UID_Person", userUid, ValType.String, CompareOperator.Equal))) _
              .Select("UID_Person", "UID_Org")
	colbeAssigments = Session.Source.GetCollection(qRoleAssigments)
	
	'If Query has Data
	If( colbeAssigments.Count = 1)
		Using uow = Session.StartUnitOfWork()
			For Each assigment As IEntity In colbeAssigments
				assigment.MarkForDeletion()
				uow.Put(assigment)
			Next
			uow.Commit()
    	End Using
				
	End If		
Next 

Parents Reply Children
  • As answered in the thread from deepak.

    The default collection load-type is read-only. That's why your code is throwing method does not exist.

    So you need to specify a different collection load-type in the GetCollection method. I suggest using bulk.

    In that case, the re-loading will be unnecessary.

    Explanation

    A collection load type can be provided as optional parameter to the GetCollection function.

    This parameter defines the contents and behavior of the loaded entities.

    Valid entity collection load types are:

    Default
    ------------------------------
    Loads read-only entities according to the supplied query. Loaded columns include the primary key,
    display columns according to the display pattern, some special columns, and the columns defined
    in the Select clause of the query. The entries will be sorted by the defined display or the optional
    OrderBy clause of the query. This load type is the default and can be omitted.

    Slim
    ------------------------------
    Works mostly like Default but does not load display columns and does not build an ORDER BY clause per default.
    This type is useful when loading data not intended for display and can save much time by using database indices.

    Bulk
    ------------------------------
    Loads entities that can be edited and saved. The loaded entities use the delayed logic mode.
    All columns will be loaded. The columns defined in the query will be overridden.

    BulkReadOnly
    ------------------------------
    Loads read-only entities with all columns filled. The columns defined in the query will be overridden.

    ForeignDisplays
    ------------------------------
    Loads display values for foreign keys contained in the display pattern too.
    This allows showing displays instead of UIDs for foreign keys.

    ForeignDisplaysForAllColumns
    ------------------------------
    Like ForeignDisplays, but loads displays for all foreign keys contained in the Select clauses of the query,
    not only columns referenced in the display pattern.

    LoadForeignDisplaysEvenWhenExpensive
    ------------------------------
    This option even loads displays for dynamic foreign keys, even when that means one additional query
    against the database for every row of the result. ATTENTION: This can be very expensive.

    Load types can be combined, but some combinations do not make sense. In that case
    the broader definition will be effective.

    For example the combination Bulk and BulkReadOnly will work like Bulk alone.