Missing DataPortal_Create(XXXX) a lot...

Missing DataPortal_Create(XXXX) a lot...

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


Izhido posted on Thursday, December 07, 2006

Hi guys!

I'm having this problem, and was hoping someone could help me find the correct solution for it.

You see, I just recently upgraded my application to use CSLA 2.1. A BIG improvement, especially on the validation/authorization rules issue (per-instance vs per-type rule loading). Everything was being cool... until I compiled the application Indifferent [:|]. I didn't noticed it when reading the change log, but there it was.

What I didn't see was this:

"I also changed the virtual/Overridable DataPortal_Create(object) method declarations in BusinessBase and BusinessListBase to DataPortal_Create(), because that’s the more common default behavior."

OUCH!

Well, actually only one of my BOs use a DataPortal_Create(XXXX) that expects to use the criteria object to gather more information. The problem is, I fully expect there will appear more and more of these objects on my application. So, now I'm at a loss of what to do next. I mean, was it that important to remove this perfectly useful method?

My question: now that DataPortal_Create(XXXX)  is gone, do you guys know of other ways to submit information other than the Criteria object to a DataPortal_Create() method (and ONLY to that specific method call), that have the same effect as if a Criteria object has been submitted to it? Preferably, one that does not force me to alter CSLA's sources (something I really prefer to avoid)? I know, I know... "use DataPortal_Fetch(XXXX) instead"... a useful solution, but not very elegant, and one that basically "clashes" with CSLA's best practices.

Any pointers you can give me to the solution will be highly appreciated. Thanks!

xal replied on Thursday, December 07, 2006

The old behaviour is there... the change is, when you don't pass a criteria, it will look for:
dataportal_xxxx() instead of dataportal_xxx(ByVal crit as Object).

Before, if you didn't pass a criteria, it falled back to a method that took a criteria of type object, now it falls back to a method with NO parameters. When you DO pass criteria, it will look for the appropiate methods.

Andrés

ajj3085 replied on Thursday, December 07, 2006

I'm not sure I follow.  You need to call DP_C, and want to pass it an object that doesn't subclass CriteriaBase?  What's the reason for not wanting to create a subclass of CriteriaBase?

Andy

Izhido replied on Thursday, December 07, 2006

xal: Ummm... that's interesting. The compile error I got after migrating was that I cannot override DataPortal_Create(XXXX) since it does not exist on BusinessBase. Checking with the "Object Browser" of VS, I could see in fact it does not exist. Should I understand, from what you told me, that Csla will look (probably through Reflection) for a "DataPortal_Create(XXXX)" method and, if it exists, will call it? Because if it is, then all I have to do is to remove the "Overrides " part of the method declaration. Is that it?

ajj: No, no. I think you didn't get it. All criteria objects I use on my application actually subclass from CriteriaBase. What I noticed was that, although the DataPortal.Create(XXXX) call actually expects a Criteria parameter, there is no longer any corresponding DataPortal_Create(XXXX) on the BusinessBase class, as of 2.1. And, somehow, I was counting on it still existing for one of my BOs. Although, if I understood xal correctly, that probably is not important anymore.

ajj3085 replied on Thursday, December 07, 2006

ahh, ok...

The solution to your problem is simple.  Just change your protected override method that is given an error to private.  That will fix the compile error.

Also, DataPortal.Create CAN be called without any parameters at all.  If you do, it will look for an override of DataPortal_Create().

Sorry for my confusion.

HTH
Andy

Izhido replied on Thursday, December 07, 2006

xal: Thanks! I completely forgot about "Overloads ". You're absolutely right!

ajj: Yes, I know that. It's just that this particular BO actually requires a DP_C with parameters, the way I designed it. Thanks anyway!

- Izhido

ajj3085 replied on Thursday, December 07, 2006

Well, just glad you got it working.  Smile [:)]

I'm a C# only I person, so I was only thinking of what might be wrong that would cause C# not to compile.  Fortunately Andres is a VB guy and got you to the proper solution.

I've been having a much harder time reading VB since .Net 2.. especially where there's more than one generic type on a class.  Wink [;)]

Izhido replied on Thursday, December 07, 2006

Hehehe...
I know exactly what you're talking about:

    Public Class ConsultasTablas
        Inherits Colecciones.Catalogos.Bases.ConsultasTablasBase(Of ConsultasTablas, Objetos.Catalogos.ConsultaTabla)

subclasses:

Public Class ConsultasTablasBase(Of ColeccionFinal As MyAppColeccion(Of ColeccionFinal, ObjetoFinal), ObjetoFinal As MyAppObjeto(Of ObjetoFinal))
        Inherits MyAppColeccion(Of ColeccionFinal, ObjetoFinal)


in turn subclasses:

Public Class MyAppColeccion(Of ColeccionFinal As Csla.BusinessListBase(Of ColeccionFinal, ObjetoFinal), ObjetoFinal As MyAppObjeto(Of ObjetoFinal))
    Inherits Csla.BusinessListBase(Of ColeccionFinal, ObjetoFinal)


Would you believe this is real code in my app? Big Smile [:D]Big Smile [:D]Big Smile [:D]

- Izhido

ajj3085 replied on Thursday, December 07, 2006

Ya, I believe it.  Vb has always been a bit wordy for me.. just one of the reasons I like C#.

xal replied on Thursday, December 07, 2006

Actually, you have to change it to overloads if you do use a criteria.

The way the dp works is:
If you pass NO criteria, it'll cal a dp_xxx that takes no params.
If you pass a criteria it will first look for a method that has a parameter of the same type as your criteria, if it finds that, that's it,. If not, it calls a dp_xxx method that takes a parameter of type Object.

Just to clarify, the criteria does not need to inherit from CriteriaBase... (unless you're doing something funny with it, like creating the class outside your business class and not calling the strong typed -generic- dp methods).

Andrés

ajj3085 replied on Thursday, December 07, 2006

xal:
Actually, you have to change it to overloads if you do use a criteria.


Only if you're using VB though Wink [;)] , although the parent seems to work with both.

Copyright (c) Marimer LLC