OnValidateFieldValue Example?

Posts   
 
    
rboarman
User
Posts: 83
Joined: 01-Feb-2005
# Posted on: 30-Apr-2007 23:19:13   

I'm using 2.0 Adapter and have a question on validation. I've written the following validation code based on the help file and some other forum posts:


public partial class UsersEntity : EntityBase2, ISerializable
    {
        protected override bool OnValidateFieldValue(int fieldIndex, object value)
        {
            bool valid = true;
            switch ((UsersFieldIndex)fieldIndex)
            {
                case UsersFieldIndex.UserName:
                    SetEntityFieldError(UsersFields.UserName.ToString(), string.Empty, false);
                    if (((string)value).Length != 2)
                    {
                        SetEntityFieldError(UsersFields.UserName.ToString(), "Code must be two characters in length", false);
                        valid = false;
                    }
                    break;
                default:
                    valid = true;
                    break;
            }
            return valid;
        }
    }

I'm getting these compile errors:

error CS0534: 'UsersEntity' does not implement inherited abstract member 'SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SetRelatedEntity(SD.LLBLGen.Pro.ORMSupportClasses.IEntity2, string)' error CS0534: 'UsersEntity' does not implement inherited abstract member 'SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.UnsetRelatedEntity(SD.LLBLGen.Pro.ORMSupportClasses.IEntity2, string, bool)' error CS0534: 'UsersEntity' does not implement inherited abstract member 'SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.GetDependingRelatedEntities()' error CS0534: 'UsersEntity' does not implement inherited abstract member 'SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.GetDependentRelatedEntities()' error CS0534: 'UsersEntity' does not implement inherited abstract member 'SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.GetMemberEntityCollections()' error CS0534: 'UsersEntity' does not implement inherited abstract member 'SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.SetRelatedEntityProperty(string, SD.LLBLGen.Pro.ORMSupportClasses.IEntity2)'

Any suggestions would be great.

Also, is there a working example of this somewhere? I checked the examples area of the site and couldn't locate any.

Thank you,

Rick

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-May-2007 05:00:38   

When using partial class no rewrite the interfaces and inheritance.

 public partial class UsersEntity
    {
          ...
     }

About the examples, I think the help's example illustrates the basic usage, as there are a lot of possible scenarios. Are you looking for someone specific?

Regards

David Elizondo | LLBLGen Support Team
rboarman
User
Posts: 83
Joined: 01-Feb-2005
# Posted on: 01-May-2007 18:28:04   

Thank you. I will try that.

As far as examples, it would be great to have a compilable running example of a web form that uses this validation method.

Rick

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-May-2007 09:16:01   

it would be great to have a compilable running example of a web form that uses this validation method.

It's hard to have a compilable example for every possible feature or a user need, but in general we have this forum built with LLBLGen Pro 2.0 and the source code is here: http://www.llblgen.com/hnd/

Also for that OnValidateFieldValue method an example is available in the docs: Using the generated code -> Validation per field or per entity

rboarman
User
Posts: 83
Joined: 01-Feb-2005
# Posted on: 02-May-2007 20:00:10   

daelmo wrote:

When using partial class no rewrite the interfaces and inheritance.

 public partial class UsersEntity
    {
          ...
     }

I tried this but it does not work either. Here is the error:

error CS0115: 'UsersEntity.OnValidateFieldValue(int, object)': no suitable method found to override

I also tried adding the namespace which didn't help either.



namespace SD.LLBLGen.Pro.ORMSupportClasses
{
    public partial class UsersEntity
    {
        protected override bool OnValidateFieldValue(int fieldIndex, object value)
        {
            bool valid = true;
            switch ((UsersFieldIndex)fieldIndex)
            {
                case UsersFieldIndex.UserName:
                    SetEntityFieldError(UsersFields.UserName.ToString(), string.Empty, false);
                    if (((string)value).Length != 2)
                    {
                        SetEntityFieldError(UsersFields.UserName.ToString(), "Code must be two characters in length", false);
                        valid = false;
                    }
                    break;
                default:
                    valid = true;
                    break;
            }
            return valid;
        }
    }
}

Am I being stupid?

Rick

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39922
Joined: 17-Aug-2003
# Posted on: 02-May-2007 21:53:49   

You shouldn't place your partial class in the ORMSupportClasses namespace, but in the same namespace as your UserEntity generated class is simple_smile . Typically that's in the rootnamespace.EntityClasses namespace.

the partial class is another part of the generated entity class, so should be in the same namespace, otherwise the compiler will think it's a new class.

Frans Bouma | Lead developer LLBLGen Pro