DataPortal.Create Failed

DataPortal.Create Failed

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


Joffies posted on Wednesday, August 23, 2006

Hi

I am new to the CSLA framework and I am trying to create and test one editable root business class based on the Project tracker example with CSLA 2.0

What are the possible reasons for the DataPortal.Create method to fail?

Public Shared Function NewAdministrator() As Administrator

If Not CanAddObject() Then

Throw New System.Security.SecurityException( _

"User not authorized to add a administrator")

End If

Return DataPortal.Create(Of Administrator)() This is where it fails

End Function

What are the possible reasons for the DataPortal.Create method to fail?

Thanks in advance

 

ajj3085 replied on Wednesday, August 23, 2006

I think there's a bug in 2.0 where the proper method isn't being looked for; try upgrading to 2.0.3, that may fix this issue.  After you upgrade, if this doesn't fix the issue, post back here again.

Joffies replied on Wednesday, August 23, 2006

Hi thanks 4 the reply.

The Project tracker sample app works fine, its only the class in my app thats doesnt work on the DataPortal.Create method.

I did however donwload the 2.03 version and this obviously doesnt correct the situation Smile [:)]

I have based my class on the Resource class in the Project tracker application.

Any pointers or ideas what might be wrong?

Ta

ajj3085 replied on Wednesday, August 23, 2006

You might be defining your DataPortal_Create wrong.   How are you defining it?  Overriding the DataPortal_Create?

Joffies replied on Wednesday, August 23, 2006

Hi Again

I have the following method defined in the Data Access region. is this the override you are referring to?

<RunLocal()> _

Private Overloads Sub DataPortal_Create(ByVal criteria As Criteria)

ValidationRules.CheckRules()

End Sub

Anything i need to change here?

ajj3085 replied on Wednesday, August 23, 2006

Hmm... I'm not a vb guru, but I think you need:

Protected Overrides etc etc.

You have Private OverLOADS.

If that doesn't work, then try

Private Sub DataPortal_Create()
End Sub

Andy

xal replied on Wednesday, August 23, 2006

The problem is that you're calling DataPortal.Create(Of xyz)() 'Without params.
If you don't pass criteria to the create, you must use the standard:

Protected Overrides Sub DataPortal_Create(ByVal criteria As Object)

you're doing:
Protected Overloads Sub DataPortal_Create(ByVal criteria As Criteria) 'Specifying criteria type.

There's nothing wrong in having a strong typed criteria in the method definition, but it won't work if you don't pass criteria.

The dataportal probes for dataportal methods in your object by trying to match the signature of the method (that's the name of the method and the types of the criteria). If you don't pass criteria, it always falls back to the standard methods defined in businessbase (which all take Object as the type of criteria)

So, you can either pass a criteria (that could be empty) object to dataportal.create or change the signature of your method. The same applies to DataPortal.Fetch(Of xyz)()

I hope it clarifies matters a bit.

Andrés

dt_matthews replied on Tuesday, September 11, 2007

hi, sorry for being slow here but I have te same problem and am trying to follow the thread advice without much joy!

My BO has this Factory method so as you see I am passing an Id (since I have read the data from an LLBLGen DAO layer) and then want to set the other properties from the LLBLGen object on the Business Object.

The exception thrown follows the method sig.

I'd really apprecaite any advice.

Thanks, dan

    Public Shared Function NewPdaSyncHistory(ByVal id As Integer) As PdaSyncHistory

        If Not CanAddObject() Then
            Throw New System.Security.SecurityException("User not authorized to add a PdaSyncHistory")
        End If
        Return DataPortal.Create(Of PdaSyncHistory)(New Criteria(id))
    End Function

<RunLocal()> _

Protected Overloads Sub DataPortal_Create(ByVal criteria As Object)

   MyBase.DataPortal_Create()

   mSyncEventId = 0

   ValidationRules.CheckRules()

End Sub

====================

Csla.DataPortalException was unhandled by user code
  Message="DataPortal.Fetch failed (Csla.DataPortalException: DataPortal.Fetch failed (Csla.DataPortalException: DataPortal.Create failed (System.NotSupportedException: Invalid operation - create not allowed
   at Csla.Core.BusinessBase.DataPortal_Create() in C:\Artemis2i\csla\Core\BusinessBase.vb:line 1185
   at Artemis2i.Library.PdaSyncHistory.DataPortal_Create(Object criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 181) ---> Csla.Server.CallMethodException: DataPortal_Create method call failed ---> System.NotSupportedException: Invalid operation - create not allowed
   at Csla.Core.BusinessBase.DataPortal_Create() in C:\Artemis2i\csla\Core\BusinessBase.vb:line 1185
   at Artemis2i.Library.PdaSyncHistory.DataPortal_Create(Object criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 181
   --- End of inner exception stack trace ---
   at Csla.Core.BusinessBase.DataPortal_Create() in C:\Artemis2i\csla\Core\BusinessBase.vb:line 1185
   at Artemis2i.Library.PdaSyncHistory.DataPortal_Create(Object criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 181
   at Csla.MethodCaller.CallMethod(Object obj, MethodInfo info, Object[] parameters) in C:\Artemis2i\csla\DataPortal\MethodCaller.vb:line 123
   at Csla.Server.SimpleDataPortal.Create(Type objectType, Object criteria, DataPortalContext context) in C:\Artemis2i\csla\DataPortal\Server\SimpleDataPortal.vb:line 52
   --- End of inner exception stack trace ---
   at Csla.Core.BusinessBase.DataPortal_Create() in C:\Artemis2i\csla\Core\BusinessBase.vb:line 1185
   at Artemis2i.Library.PdaSyncHistory.DataPortal_Create(Object criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 181
   at Csla.MethodCaller.CallMethod(Object obj, MethodInfo info, Object[] parameters) in C:\Artemis2i\csla\DataPortal\MethodCaller.vb:line 123
   at Csla.Server.SimpleDataPortal.Create(Type objectType, Object criteria, DataPortalContext context) in C:\Artemis2i\csla\DataPortal\Server\SimpleDataPortal.vb:line 52
   at Csla.DataPortal.Create(Type objectType, Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 121
   at Csla.DataPortal.Create[T](Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 67
   at Artemis2i.Library.PdaSyncHistory.NewPdaSyncHistory(Int32 id) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 120
   at Artemis2i.Library.PdaSyncHistoryList.Fetch(DateTime dateFilter) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistoryList.vb:line 91
   at Artemis2i.Library.PdaSyncHistoryList.DataPortal_Fetch(Criteria criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistoryList.vb:line 60) ---> Csla.Server.CallMethodException: DataPortal_Fetch method call failed ---> Csla.DataPortalException: DataPortal.Create failed (System.NotSupportedException: Invalid operation - create not allowed
   at Csla.Core.BusinessBase.DataPortal_Create() in C:\Artemis2i\csla\Core\BusinessBase.vb:line 1185
   at Artemis2i.Library.PdaSyncHistory.DataPortal_Create(Object criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 181) ---> Csla.Server.CallMethodException: DataPortal_Create method call failed ---> System.NotSupportedException: Invalid operation - create not allowed
   at Csla.Core.BusinessBase.DataPortal_Create() in C:\Artemis2i\csla\Core\BusinessBase.vb:line 1185
   at Artemis2i.Library.PdaSyncHistory.DataPortal_Create(Object criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 181
   --- End of inner exception stack trace ---
   at Csla.Core.BusinessBase.DataPortal_Create() in C:\Artemis2i\csla\Core\BusinessBase.vb:line 1185
   at Artemis2i.Library.PdaSyncHistory.DataPortal_Create(Object criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 181
   at Csla.MethodCaller.CallMethod(Object obj, MethodInfo info, Object[] parameters) in C:\Artemis2i\csla\DataPortal\MethodCaller.vb:line 123
   at Csla.Server.SimpleDataPortal.Create(Type objectType, Object criteria, DataPortalContext context) in C:\Artemis2i\csla\DataPortal\Server\SimpleDataPortal.vb:line 52
   --- End of inner exception stack trace ---
   at Csla.Core.BusinessBase.DataPortal_Create() in C:\Artemis2i\csla\Core\BusinessBase.vb:line 1185
   at Artemis2i.Library.PdaSyncHistory.DataPortal_Create(Object criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 181
   at Csla.MethodCaller.CallMethod(Object obj, MethodInfo info, Object[] parameters) in C:\Artemis2i\csla\DataPortal\MethodCaller.vb:line 123
   at Csla.Server.SimpleDataPortal.Create(Type objectType, Object criteria, DataPortalContext context) in C:\Artemis2i\csla\DataPortal\Server\SimpleDataPortal.vb:line 52
   at Csla.DataPortal.Create(Type objectType, Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 121
   at Csla.DataPortal.Create[T](Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 67
   at Artemis2i.Library.PdaSyncHistory.NewPdaSyncHistory(Int32 id) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 120
   at Artemis2i.Library.PdaSyncHistoryList.Fetch(DateTime dateFilter) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistoryList.vb:line 91
   at Artemis2i.Library.PdaSyncHistoryList.DataPortal_Fetch(Criteria criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistoryList.vb:line 60
   --- End of inner exception stack trace ---
   at Csla.Core.BusinessBase.DataPortal_Create() in C:\Artemis2i\csla\Core\BusinessBase.vb:line 1185
   at Artemis2i.Library.PdaSyncHistory.DataPortal_Create(Object criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 181
   at Csla.MethodCaller.CallMethod(Object obj, MethodInfo info, Object[] parameters) in C:\Artemis2i\csla\DataPortal\MethodCaller.vb:line 123
   at Csla.Server.SimpleDataPortal.Create(Type objectType, Object criteria, DataPortalContext context) in C:\Artemis2i\csla\DataPortal\Server\SimpleDataPortal.vb:line 52
   at Csla.DataPortal.Create(Type objectType, Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 121
   at Csla.DataPortal.Create[T](Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 67
   at Artemis2i.Library.PdaSyncHistory.NewPdaSyncHistory(Int32 id) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 120
   at Artemis2i.Library.PdaSyncHistoryList.Fetch(DateTime dateFilter) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistoryList.vb:line 91
   at Artemis2i.Library.PdaSyncHistoryList.DataPortal_Fetch(Criteria criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistoryList.vb:line 60
   at Csla.MethodCaller.CallMethod(Object obj, MethodInfo info, Object[] parameters) in C:\Artemis2i\csla\DataPortal\MethodCaller.vb:line 123
   at Csla.Server.SimpleDataPortal.Fetch(Type objectType, Object criteria, DataPortalContext context) in C:\Artemis2i\csla\DataPortal\Server\SimpleDataPortal.vb:line 116
   --- End of inner exception stack trace ---
   at Csla.Core.BusinessBase.DataPortal_Create() in C:\Artemis2i\csla\Core\BusinessBase.vb:line 1185
   at Artemis2i.Library.PdaSyncHistory.DataPortal_Create(Object criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 181
   at Csla.MethodCaller.CallMethod(Object obj, MethodInfo info, Object[] parameters) in C:\Artemis2i\csla\DataPortal\MethodCaller.vb:line 123
   at Csla.Server.SimpleDataPortal.Create(Type objectType, Object criteria, DataPortalContext context) in C:\Artemis2i\csla\DataPortal\Server\SimpleDataPortal.vb:line 52
   at Csla.DataPortal.Create(Type objectType, Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 121
   at Csla.DataPortal.Create[T](Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 67
   at Artemis2i.Library.PdaSyncHistory.NewPdaSyncHistory(Int32 id) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 120
   at Artemis2i.Library.PdaSyncHistoryList.Fetch(DateTime dateFilter) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistoryList.vb:line 91
   at Artemis2i.Library.PdaSyncHistoryList.DataPortal_Fetch(Criteria criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistoryList.vb:line 60
   at Csla.MethodCaller.CallMethod(Object obj, MethodInfo info, Object[] parameters) in C:\Artemis2i\csla\DataPortal\MethodCaller.vb:line 123
   at Csla.Server.SimpleDataPortal.Fetch(Type objectType, Object criteria, DataPortalContext context) in C:\Artemis2i\csla\DataPortal\Server\SimpleDataPortal.vb:line 116
   at Csla.DataPortal.Fetch(Type objectType, Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 204
   at Csla.DataPortal.Fetch[T](Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 148
   at Artemis2i.Library.PdaSyncHistoryList.GetPdaSyncHistoryList() in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistoryList.vb:line 19
   at Artemis2i.Library.Nurse.DataPortal_Fetch(Criteria criteria) in C:\Artemis2i\Artemis2iLib\Nurse\Nurse.vb:line 375)"
  Source="Csla"
  StackTrace:
       at Csla.Core.BusinessBase.DataPortal_Create() in C:\Artemis2i\csla\Core\BusinessBase.vb:line 1185
       at Artemis2i.Library.PdaSyncHistory.DataPortal_Create(Object criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 181
       at Csla.MethodCaller.CallMethod(Object obj, MethodInfo info, Object[] parameters) in C:\Artemis2i\csla\DataPortal\MethodCaller.vb:line 123
       at Csla.Server.SimpleDataPortal.Create(Type objectType, Object criteria, DataPortalContext context) in C:\Artemis2i\csla\DataPortal\Server\SimpleDataPortal.vb:line 52
       at Csla.DataPortal.Create(Type objectType, Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 121
       at Csla.DataPortal.Create[T](Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 67
       at Artemis2i.Library.PdaSyncHistory.NewPdaSyncHistory(Int32 id) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistory.vb:line 120
       at Artemis2i.Library.PdaSyncHistoryList.Fetch(DateTime dateFilter) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistoryList.vb:line 91
       at Artemis2i.Library.PdaSyncHistoryList.DataPortal_Fetch(Criteria criteria) in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistoryList.vb:line 60
       at Csla.MethodCaller.CallMethod(Object obj, MethodInfo info, Object[] parameters) in C:\Artemis2i\csla\DataPortal\MethodCaller.vb:line 123
       at Csla.Server.SimpleDataPortal.Fetch(Type objectType, Object criteria, DataPortalContext context) in C:\Artemis2i\csla\DataPortal\Server\SimpleDataPortal.vb:line 116
       at Csla.DataPortal.Fetch(Type objectType, Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 204
       at Csla.DataPortal.Fetch[T](Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 148
       at Artemis2i.Library.PdaSyncHistoryList.GetPdaSyncHistoryList() in C:\Artemis2i\Artemis2iLib\Pda\PdaSyncHistoryList.vb:line 19
       at Artemis2i.Library.Nurse.DataPortal_Fetch(Criteria criteria) in C:\Artemis2i\Artemis2iLib\Nurse\Nurse.vb:line 375
       at Csla.MethodCaller.CallMethod(Object obj, MethodInfo info, Object[] parameters) in C:\Artemis2i\csla\DataPortal\MethodCaller.vb:line 123
       at Csla.Server.SimpleDataPortal.Fetch(Type objectType, Object criteria, DataPortalContext context) in C:\Artemis2i\csla\DataPortal\Server\SimpleDataPortal.vb:line 116
       at Csla.DataPortal.Fetch(Type objectType, Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 204
       at Csla.DataPortal.Fetch[T](Object criteria) in C:\Artemis2i\csla\DataPortal\Client\DataPortal.vb:line 148
       at Artemis2i.Library.Nurse.GetNurse(Int32 ID) in C:\Artemis2i\Artemis2iLib\Nurse\Nurse.vb:line 265
       at Artemis2i.PL.NursePL.Nurse_Select(Int32 NurseId) in C:\Artemis2i\Artemis2iPL\NursePL.vb:line 15
       at WebControls_NurseDetails.PopulateNurseDetailsForm(Int32 NurseId) in C:\Artemis2i\Web\WebControls\NurseMainDetails.ascx.vb:line 82
       at WebControls_NurseDetails.Page_Load(Object sender, EventArgs e) in C:\Artemis2i\Web\WebControls\NurseMainDetails.ascx.vb:line 146
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

richardb replied on Tuesday, September 11, 2007

Looking at your code, you don't need the MyBase.DataPortal_Create as you are not getting any defaults here for your object from the database.  Although if you did want to, you'd just write code like the stuff typically placed in the Fetch statement.

Here's a C# version.

//If you don't need to go to DataSource to get defaults, specify the RunLocal attribute
//as this optimises and removes the call to the DataPortal.
//If you do make a DataPortal call you MUST remove the RunLocal attribute.
[RunLocal()]
protected override void DataPortal_Create()
{
_id = Guid.NewGuid();
_publishdate.Date = DateTime.Today;
ValidationRules.CheckRules();
}

Richard.

RockfordLhotka replied on Tuesday, September 11, 2007

If you look in Chapter 4 of the book, you'll see that the base class implementations of the DataPortal_XYZ methods all throw exceptions. This is on purpose, as it helps debug scenarios where you forgot to overload/override the base method.

A side-effect of this, is that you can't call the base implementation - because doing so will result in that exception being thrown.

dt_matthews replied on Wednesday, September 12, 2007

thanks Rocky! if my co-developer hadn't borrowed my book and not returned it I would have hopefully found it out for myself!!!!

 

regards,

dan

elnoegarcia replied on Tuesday, September 11, 2007

Hi!!

The problem is that the editor shows an error if you try to override that method, no matter if you specify the parameter or not. The message says:

"sub 'Dataportal_Create' cannot be declared 'Overrides' because it does not override a sub in a base class"

The editor offer 2 solutions, change Overrides for Overloads or left the signature without Overrides or Overloads (just Private Sub Dataportal_Create()).

I recommend that Joffies only has to use Overloads and delete the argument from the declaration of DataPortal_Create() or specify a new Criteria object when he calls the DataPortal.Create function (method).

I don't understand why this is happenin' because I review the clases in the CSLA framework (the generic BusinessBase class and BusinessBase class in the Core namespace) and the methods are marked with "Protected Overridable" and I don't know what's going on...

Noé

RockfordLhotka replied on Tuesday, September 11, 2007

To override a method you must use the exact same method signature of the base class. This is not what you are trying to do.

 

Instead, you are trying to create a new method with the same name, but a different signature. This is an overload.

 

VB requires that you use the Overloads keyword in that case to explicitly state your intent to overload the base class method. This is for clarity of code.

 

C# does not have a comparable overloads keyword, which I think is less explicit (doesn’t show the developer’s intent), but does save some typing.

 

In any case, if you aren’t matching the method signature of the base class method, then you aren’t overriding, you are overloading.

 

Rocky

 

 

From: elnoegarcia [mailto:cslanet@lhotka.net]
Sent: Tuesday, September 11, 2007 12:13 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] DataPortal.Create Failed

 

Hi!!

The problem is that the editor shows an error if you try to override that method, no matter if you specify the parameter or not. The message says:

"sub 'Dataportal_Create' cannot be declared 'Overrides' because it does not override a sub in a base class"

The editor offer 2 solutions, change Overrides for Overloads or left the signature without Overrides or Overloads (just Private Sub Dataportal_Create()).

I recommend that Joffies only has to use Overloads and delete the argument from the declaration of DataPortal_Create() or specify a new Criteria object when he calls the DataPortal.Create function (method).

I don't understand why this is happenin' because I review the clases in the CSLA framework (the generic BusinessBase class and BusinessBase class in the Core namespace) and the methods are marked with "Protected Overridable" and I don't know what's going on...

Noé


elnoegarcia replied on Wednesday, September 12, 2007

You're right Rocky!!Yes [Y]

I changed a method in one of my projects to the same signature (using Protected and Overrides) for the DataPortal_Create() (without parameters), i noticed that the problem was in the visibility modifier (Protected).

best regards...
NoeBig Smile [:D]

Copyright (c) Marimer LLC