DataPortal_Create error

DataPortal_Create error

Old forum URL: forums.lhotka.net/forums/t/2131.aspx


TerryHolland posted on Friday, January 12, 2007

Im getting the following error when I try to create a new EditableRoot object

DataPortal.Create failed (System.NotSupportedException: Invalid operation - create not allowed
   at Csla.Core.BusinessBase.DataPortal_Create())

The code I have is straight from the template and all other sections seem to work.

When stepping through the code I put a break point on the line

Protected Overloads Sub DataPortal_Create(ByVal objCriteria As Object)

but execution never gets to here.

Im getting around at the minute by changing my New factory method to

   Public Shared Function NewItem() As clsItem
        If Not CanAddObject() Then
            Throw New System.Security.SecurityException("User not authorized to add a Item")
        End If
        Return New clsItem

        'todo: broken - awaiting support
        'Return DataPortal.Create(Of clsItem)()
    End Function

Any ideas?

ajj3085 replied on Friday, January 12, 2007

You want

Protected Overrides Sub DataPortal_Create()

Not Overloads.  You also dont' want to specify any criteria, becausey ou are calling DP.C(Of T) without parameters.

TerryHolland replied on Friday, January 12, 2007

Are you sure?

The project tracker project has it exactly as I have imported from codesmith templates.  And all of my DataPortal_XYZ  functions are similarly declared

ajj3085 replied on Friday, January 12, 2007

Positive.  I don't think the example has been updated to keep pace with changes to the most recent code.  You're on 2.1.1 correct? 

Because you're calling DP.C without parameters, the default DP_C method (with no parameters) is being called, and its default implementation is to throw the exception you're seeing.  Check out Csla.Core.BusinessBase, and you'll find a Protected Overridable DataPortal_Create() method.

Andy

TerryHolland replied on Friday, January 12, 2007

I get a compile error when I replace Overloads with Overrides

Error 4 sub 'DataPortal_Create' cannot be declared 'Overrides' because it does not override a sub in a base class. D:\_Development\Contest\v03\Dev\Contest\Contest.Library\CSLA Root Child Test\clsItem.vb 531 29 Contest.Library

Im not sure what version Im on - how do I tell?

ajj3085 replied on Friday, January 12, 2007

Did you also remove the parameter list on your method?

TerryHolland replied on Friday, January 12, 2007

Whoops.  Works OK now.  So should the other DataPortal_ methods be declared overrides instead of Overloads?

In fact, it works fine with Overloads as long as the parameter is removed

ajj3085 replied on Friday, January 12, 2007

Hmm... that must be a VB thing.  In C#, you'd get a compile warning because have a new member (the Overloadd one) conflicting with the inhertied member.

Fetch has been changed too; see the changelog for details.

TerryHolland replied on Friday, January 12, 2007

OK.

Thanks for your help

RockfordLhotka replied on Friday, January 12, 2007

ajj3085:
Hmm... that must be a VB thing.  In C#, you'd get a compile warning because have a new member (the Overloadd one) conflicting with the inhertied member.

Fetch has been changed too; see the changelog for details.

No, the warning should appear in VB too - something about the method being in conflict and behind automatically shadowed by the subclass. But it is just a warning, not an error, so if you don't have the switch set to treat warnings like errors you might not notice it right away.

TerryHolland replied on Friday, January 12, 2007

My version is 2.1.0.0

ajj3085 replied on Friday, January 12, 2007

See the changelog; the changes which are causing you grief happened on 2.1.0.  The first two items in that list are what differs from the example.

Copyright (c) Marimer LLC