Inheritance and abstract entity

Posts   
 
    
jbliss1234
User
Posts: 42
Joined: 04-May-2007
# Posted on: 02-Apr-2009 02:46:26   

Please consider the attached .lgp file.

I have a base abstract class called Widget, and 3 derived classes.

Problem #1 The Widget class is marked as abstract, however, I can still instantiate it like so:

m_Widget = New WidgetEntity(New Guid(WidgetId))

Is this a bug?

Problem #2 ForumWidget, and FormWidget are derived classes of Widget. If Widget entity were to be abstract, and all I have is a widgetid primary key, is there a best practice pattern to give me an instance of a appropriate derived class. Do I have to do something like a case statement?

Using LLBLGen Pro 2.6 June6th 2008 SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll version 2.6.0.0 File Version 2.6.08.0624 SD.LLBLGen.Pro.DQE.SqlServer.NET20.dll version 2.6.0.0 File Version 2.6.08.0612

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Apr-2009 05:43:18   

jbliss1234 wrote:

Problem #1 The Widget class is marked as abstract, however, I can still instantiate it like so:

m_Widget = New WidgetEntity(New Guid(WidgetId))

Is this a bug?

This is the answer: http://llblgen.com/tinyforum/Messages.aspx?ThreadID=12579

jbliss1234 wrote:

Problem #2 ForumWidget, and FormWidget are derived classes of Widget. If Widget entity were to be abstract, and all I have is a widgetid primary key, is there a best practice pattern to give me an instance of a appropriate derived class. Do I have to do something like a case statement?

LLBLGen Pro uses Polymorphic Fetches which means that if the someEntity, for instance customer "CHOPS", has references to instances of different derived types of Order, every instance in customer.Orders is of the type it represents, which effectively means that not every instance in Orders is of the same type. In that case you could perform a cast, or switch.

David Elizondo | LLBLGen Support Team
jbliss1234
User
Posts: 42
Joined: 04-May-2007
# Posted on: 03-Apr-2009 01:57:03   

For problem#1, I should have clarified that I am able to create an instance of the WidgetEntity from ASP.Net. Therefore, the message you have quoted does not apply. This is definitely a bug, as I do not see any contructors marked "internal"

public WidgetEntity():base()
        {
        }

    
        /// <summary>
        /// CTor
        /// </summary>
        /// <param name="widgetId">PK value for Widget which data should be fetched into this Widget object</param>
        public WidgetEntity(System.Guid widgetId):
            base(widgetId)
        {
        }


        /// <summary>
        /// CTor
        /// </summary>
        /// <param name="widgetId">PK value for Widget which data should be fetched into this Widget object</param>
        /// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
        public WidgetEntity(System.Guid widgetId, IPrefetchPath prefetchPathToUse):
            base(widgetId, prefetchPathToUse)
        {
        }


        /// <summary>
        /// CTor
        /// </summary>
        /// <param name="widgetId">PK value for Widget which data should be fetched into this Widget object</param>
        /// <param name="validator">The custom validator object for this WidgetEntity</param>
        public WidgetEntity(System.Guid widgetId, IValidator validator):
            base(widgetId, validator)
        {
        }
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 03-Apr-2009 10:56:14   

Reopened. please don't start new threads if they simply continue your original.

Looking into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 03-Apr-2009 10:59:28   

Indeed a bug. it should have been internal in the derived entity as well. Will work on fix. (this bug is in the templates at least since 1.0.2005.1, no-one noticed it flushed )

btw, your runtime libs are outdated please use the latest build. (not related to your problem, but they'll fix some issues you might run into).

(edit) please use the fixed template attached to this post. place the template in the Templates\Shared templates\Net 2.x\C# folder overwriting the existing one.

Attachments
Filename File size Added on Approval
entityUsingEntityBase.template 5,143 03-Apr-2009 11:04.41 Approved
Frans Bouma | Lead developer LLBLGen Pro