Object Reference Required for Non-Static field

Posts   
 
    
NickD
User
Posts: 224
Joined: 31-Jan-2005
# Posted on: 02-Jun-2006 20:08:54   

Adapter Beta May 25th, 2006

I've been using the beta generator fine now on three small projects. However, in this most recent generation of a brand new project, one class is generating a:

"An object reference is required for the nonstatic field, method or property 'HLPUSD.BOSS.DAL.EntityClasses.PersonContactEntity.RelationType.get'"

when it compiles. Here is the "offending" line of code:

/// <summary> Creates a new PrefetchPathElement2 object which contains all the information to prefetch the related entities of type 'CdRelationshipType' 
        /// for this entity. Add the object returned by this property to an existing PrefetchPath2 instance.</summary>
        /// <returns>Ready to use IPrefetchPathElement2 implementation.</returns>
        public static IPrefetchPathElement2 PrefetchPathCdRelationshipType
        {
            get
            {
                return new PrefetchPathElement2(new EntityCollection(new CdRelationshipTypeEntityFactory()),
                    PersonContactEntity.Relations.CdRelationshipTypeEntityUsingRelationType, 
                    (int)HLPUSD.BOSS.DAL.EntityType.PersonContactEntity, (int)HLPUSD.BOSS.DAL.EntityType.CdRelationshipTypeEntity, 0, null, null, null, null, "CdRelationshipType", RelationType.ManyToOne);
            }
        }

...which looks like all the other generated lines of code in the other entities. What in my database do you think has confused things?

Also, I get a compiler error on the "RelationType.ManyToOne" that says:

"'string' does not contain a definition for 'ManyToOne'"

...I've checked all my references and they appear OK.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39898
Joined: 17-Aug-2003
# Posted on: 02-Jun-2006 20:33:05   

It's a silly error by the C# compiler, it can't figure out that an enum is meant. You have a field in the entity, called 'RelationType'. The statement 'RelationType.ManyToOne', thinks the code is referring to the property 'RelationType', however it's referring to SD.LLBLGen.Pro.ORMSupportClasses.RelationType.

So either rename RelationType in your entity to a different name, or wait till I've prefixed it in the templates with the full name of the type simple_smile .

Frans Bouma | Lead developer LLBLGen Pro
NickD
User
Posts: 224
Joined: 31-Jan-2005
# Posted on: 02-Jun-2006 22:39:12   

Otis wrote:

So either rename RelationType in your entity to a different name, or wait till I've prefixed it in the templates with the full name of the type simple_smile .

...or I could edit the templates myself smile Once I did that, it worked. Gracias.