Override OnBeforeEntitySave

Posts   
 
    
SyRo
User
Posts: 2
Joined: 11-May-2006
# Posted on: 16-May-2006 16:50:36   

First, LLBLgen is a great pice of work!

I have a little question. I'm using the adapter version of the generated code. Now i want to make my DataAccessAdapter class that inherits from the DatabaseSpecific DataAccessAdapter so i can override the OnBeforeEntitySave.

But when I try to compile the code i get the following error: sub 'OnBeforeEntitySave' cannot be declared 'Overrides' because it does not override a sub in a base class. This is my code:


Imports System
Imports SD.LLBLGen.Pro.ORMSupportClasses
Imports Ism.Prisma.Collaboration.DatabaseSpecific

Public Class TestDataAccessAdapter
    Inherits DataAccessAdapter

    Public Sub New()
        MyBase.New()
    End Sub

    Public Overrides Sub OnBeforeEntitySave(ByVal entitySaved As SD.LLBLGen.Pro.ORMSupportClasses.IEntity2, ByVal insertAction As Boolean)

        MyBase.OnBeforeEntitySave(entitySaved, insertAction)
    End Sub

End Class

when I remove Overrides, I get the following warning: sub 'OnBeforeEntitySave' shadows an overridable method in the base class 'DataAccessAdapterBase'. To override the base method, this method must be declared 'Overrides'.

confused

What must I do to get this to work? Using .net framework 2.0, VS 2005, LLBLGEN version 1.0.2005.1 (runtime v2.0.50727)

by the way when I try to do it in a c# class (and project) it will compile.


using System;
using Ism.Prisma.Collaboration.DatabaseSpecific;
using SD.LLBLGen.Pro.ORMSupportClasses;

public class TestDataAccessAdapter : DataAccessAdapter
{
    public TestDataAccessAdapter()
        : base()
    {}


    public override void OnBeforeEntitySave(IEntity2 entityToSave, bool isInsert)
    {}
}

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 16-May-2006 17:38:51   

I can't reproduce it:


    Public Class TestAdapter
        Inherits DataAccessAdapter

        Public Overrides Sub OnBeforeEntitySave(ByVal entityToSave As IEntity2, ByVal isInsert As Boolean)
            MyBase.OnBeforeEntitySave(entityToSave, isInsert)
        End Sub
    End Class

compiles fine. Also different names of isInsert didn't make a difference (thankfully)

I placed this class in the same file as DataAccessAdapter, though outside that class of course.

If you place your class in teh same file (for testing) does it work then? Do you use C# generated code with VB.NET in 1 solution perhaps?

Frans Bouma | Lead developer LLBLGen Pro
SyRo
User
Posts: 2
Joined: 11-May-2006
# Posted on: 17-May-2006 09:24:45   

When I place the code in the same file as the DataAccessAdapter it works. (inside or outside the namespace). When I add to the code a must MustOverride method, and MustInherit to the class. Like this:


Public MustInherit Class TestAdapter
    Inherits Ism.Prisma.Collaboration.DatabaseSpecific.DataAccessAdapter

    Public Overrides Sub OnBeforeEntitySave(ByVal entityToSave As IEntity2, ByVal isInsert As Boolean)
        myOnBeforeEntitySave(entityToSave, isInsert)
        MyBase.OnBeforeEntitySave(entityToSave, isInsert)
    End Sub

    Public MustOverride Sub myOnBeforeEntitySave(ByVal entityToSave As IEntity2, ByVal isInsert As Boolean)

End Class

And try to inherit from that class:


Public Class TestDataAccessAdapter
    Inherits TestAdapter

    Public Overrides Sub myOnBeforeEntitySave(ByVal entityToSave As SD.LLBLGen.Pro.ORMSupportClasses.IEntity2, ByVal isInsert As Boolean)
    End Sub

End Class

I got the following two errors: _ Error 1 Class 'TestDataAccessAdapter' must either be declared 'MustInherit' or override the following inherited 'MustOverride' member(s): TestAdapter : Public MustOverride Sub myOnBeforeEntitySave(entityToSave As SD.LLBLGen.Pro.ORMSupportClasses.IEntity2, isInsert As Boolean).

Error 2 sub 'myOnBeforeEntitySave' cannot be declared 'Overrides' because it does not override a sub in a base class. _

So this does't workcry

But when i copy the file from my project to the CollaborationDBSpecific project it will work. Does any one know that this is a bug in .NET??

I try to look at the properties of the CollaborationDBSpecific project and my project they look the same.

O I also tried to override the function OnAfterTransactionCommit, and that works. Only the functions that have parameters I can’t override.

For generation i use the following settings: Name: Adapter scenario (Full / Safe) Vs.Net 2005 Version: 1.0.2005.1.03032006

Name: VB.NET template set for SqlServer (1.0.2005.1) Version: 1.0.2005.1.102305

I hope that I gave you enough information. If no one have the same problem or no one can help my, its oke. Then I must use the more ugly method and put my class at the bottom of the DataAccessAdapter file.

Thanks for the support.