Hi guys.
I tried to implement an override in my own BusinessBase class defined as follows
public
abstract class EQBusinessBase<T> : Csla.BusinessBase<T> where T : EQBusinessBase<T>All my objects are based on this instead of BusinessBase, and this lets me customise/add features wiothout modifying Csla code. Today I tried to do
protected
override void DataPortal_Fetch(object criteria)But the code never gets hit. Can someone tell me why? Other stuff in the class works fine.
Thanks.
P.S. FWIW, I am trying to get a reference to the name of the DataPortal xyz method currently being executed within the DataPortal_OnDataPortalInvoke event of a Business Object, and figured I could store this in the ApplicationContext.GlobalContext for want of another way to do this. The event tells you that a xyz method is being excuted, but not which one. This is what I was trying to in the Fetch overrride. If someone could suggest a way to do this then that would be great too.
John.
This may seem like an obvious question, but are you going through one of the standard factory methods and calling the DataPortal ?
For example:
public static AvailableRoom GetAvailableRoom(int roomId)
{
return CSLA.DataPortal.Fetch<AvailableRoom>(new CriteriaIntIdentity(typeof(AvailableRoom), roomId));
}
Have you stepped through this code and had a break point set in the DataPortal_Fetch?
Hi David
Yes I am calling a factory method and I have tried a breakpoint in DataPortal_Fetch of my BO class. It hits that one OK but not the one in my base class.
John.
So you've got an override for DataPortal_Fetch() in your BO class as well as in your abstract base class (ABC). In that case the method in the ABC will never be called because it will always call the instance method version, which is the one for your BO.
In the DataPortal_Fetch() override in your BO class you need to explicitly call the method in the ABC.
Add something like this to your code:
base.DataPortal_Fetch(criteria)
The DataPortal_Fetch in the BOo class is not an override, just a method with that name. The abstract base class has the overrride version. But I think I understand. Why is it that with some classes of BO you seem to need to do an overrride of Fetch whereas with others you don't?
The DataPortal_Fetch in the BO class should be declared override.
Otherwise you're hiding the method in the base class. This generates a compiler warning which can be suppressed by using the "new" modifier. Check the MSDN for "new modifier keyword (C#)" in the C# Programmer's Reference.
Do you not get the compiler warning?
DOH! Of course Rocky's right and that explains what's going on!
You're not getting the compiler warning because the method in your BO is an overload not an override.
And that's also why it never calls the method in the ABC.
The problem is that there's a quirk in the way reflection interacts with generics... It turns out that reflection won't find a method implemented in a base class if that base class is both abstract and generic (which is your case).
I've been working with Ricky Supit on solving this, and there's a prototype solution in cvs for C# at the moment (www.lhotka.net/cslacvs) so you can try that. I think I did the same thing for VB, but I don't recall for sure (the last couple weeks I've been flying so much I'm kind of blurry...).
In any case, you can expect the fix to be in version 2.0.1 (basically a bug fix release) within the next couple weeks.
Copyright (c) Marimer LLC