CreateValidator

Posts   
 
    
pandu avatar
pandu
User
Posts: 86
Joined: 18-May-2006
# Posted on: 09-Nov-2006 06:44:12   

How do I add CreateValidator Class without touching the generated Entity Classes?

From Manual...

Entity classes don't get a validator instance by default, even if you generate them through LLBLGen Pro. To automate the creation of an entity's validator object when you instantiate an entity, you should override the method CreateValidator in the entity class, either through a partial class, include template or by adding code to the custom code user code region of the generated entity classes.

Partial Class? How do I add partial class for EntityClass?

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-Nov-2006 07:16:28   

It's a .Net 2.0 feature: Add new file containg the same class definition of the entity class in question but with the use of the keyword partial

Have a look at how the entity classes are defined in the generated code. You will find the keyword partial used.

Ref: http://msdn2.microsoft.com/en-US/library/wa80x488.aspx

pandu avatar
pandu
User
Posts: 86
Joined: 18-May-2006
# Posted on: 09-Nov-2006 08:57:53   

Ok.

I have created a new file with the following:

Partial Class SeasonEntity

    Protected Overrides Function CreateValidator() As IValidator
        Return Nothing
    End Function

End Class

SeasonEntity is my generated Entity Class. This gives me an error:

CreateValidator cannot be declared as Overrides.

I changed the Partial Class as:

#If CF Then
    <SD.LLBLGen.Pro.ORMSupportClasses.Serializable()> _
    Public Class SeasonEntity 
#Else
<Serializable()> _
Partial Public Class SeasonEntity
#End If
    Inherits EntityBase2

    Protected Overrides Function CreateValidator() As IValidator
        Return Nothing
    End Function

End Class

This gives the following error:

Class 'SeasonEntity' must either be declared 'MustInherit' or override the following inherited 'MustOverride' member(s): 
    SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2 : Public MustOverride Function GetDependentRelatedEntities() As System.Collections.Generic.List(Of SD.LLBLGen.Pro.ORMSupportClasses.IEntity2)
    SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2 : Public MustOverride Function GetDependingRelatedEntities() As System.Collections.Generic.List(Of SD.LLBLGen.Pro.ORMSupportClasses.IEntity2)
    SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2 : Public MustOverride Function GetMemberEntityCollections() As System.Collections.Generic.List(Of SD.LLBLGen.Pro.ORMSupportClasses.IEntityCollection2)
    SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2 : Public MustOverride Sub SetRelatedEntity(relatedEntity As SD.LLBLGen.Pro.ORMSupportClasses.IEntity2, fieldName As String)
    SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2 : Public MustOverride Sub SetRelatedEntityProperty(propertyName As String, entity As SD.LLBLGen.Pro.ORMSupportClasses.IEntity2)
    SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2 : Public MustOverride Sub UnsetRelatedEntity(relatedEntity As SD.LLBLGen.Pro.ORMSupportClasses.IEntity2, fieldName As String, signalRelatedEntityManyToOne As Boolean).    

Help please... flushed

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 09-Nov-2006 09:23:49   

What's the llblgen pro version? In v2.0, CreateValidator is virtual, so your initial partial class is correct. So I think it's not recognized as a partial class of an existing class.

The second version you posted doesn't work as it inherits again from EntityBase2, a partial class is a second codefile for the same class. You therefore have to place it in the same namespace and PROJECT as the generated code. Did you do that?

Frans Bouma | Lead developer LLBLGen Pro
pandu avatar
pandu
User
Posts: 86
Joined: 18-May-2006
# Posted on: 10-Nov-2006 06:54:00   

I was having that file outside the PROJECT where generated entity is.

I moved it inside the PROJECT and it works fine.

Thank you. simple_smile