IEntity2.IsCool

Posts   
 
    
Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 05-Jan-2012 19:52:47   

Hello all,

I have been searching for the past several hours and I have a simple question:

I want to add a single boolean property to IEntity2, resulting in code similar to

internal static void CheckIfEntityCool(IEntity2 entity)
        {
                if (entity.IsCool)
                {
                        //Code here!
                        entity.IsCool = false;
                }
        }

Definition of property is:

public bool IsCool { get; set; }

How can I achieve this?

LLBLGen Pro version: 3.0 / August 18th, 2010 .Net Version: 3.5

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Jan-2012 22:14:22   

Hi Bashar,

Some options:

A. Use the generated CommonEntityBase class and add the property to it as virtual in the USER_CODE_REGION (or a partial class). Then override it on the entities you want to implement it.

B. Use your own interface (let say IMyCool) and lets the CommonEntityBase implement it in a partial class. You also could use the Code gen. meta-data defaults Tab to do this for all entities from the Designer.

internal static void CheckIfEntityCool(IMyCool entity)
        {
                if (entity.IsCool)
                {
                        //Code here!
                        entity.IsCool = false;
                }
        }
David Elizondo | LLBLGen Support Team
Bashar
User
Posts: 108
Joined: 11-Nov-2004
# Posted on: 07-Jan-2012 11:12:14   

Hi David,

Thank you for your reply, however, this does not achieve what I wanted. I want to send an object of type IEntity2 to the function and check against that.

Implementing my own interface will require much more coding, which is unfeasible.

Another option please smile

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Jan-2012 21:24:03   

Bashar wrote:

Implementing my own interface will require much more coding, which is unfeasible.

IMHO it'is not that much code. All you have to do is write the interface, which in your case would contain only one property. Then in LLBLGen Designer you assign an Interface for Entities at project level, that means all your entity classes will contain that interface. Then all you have to do is implement it, you can do that per-entity and also in the base CommonEntityBase class, you have to do this anyway even if it would be possible to extend IEntity2. So that is not a lot of code. The benefit is that this is per project, so you don't have to worry about new projects when you don't need this. Besides the behaviors remain separated: An IEntity should behave like an IEntity, an IMyCool describes another behavior, so you don't mix things. If you modify IEntity2, that would break older and newer projects code. So that is the recommended approach.

If you really need to alter IEntity2 then you have to download ORMSupportClasses sourceCode (from customer area) and do that by yourself, then use that compiled assembly in you project instead of the shipped one. The problem is: if you want to update to a newer runtime libraries version, you have to repeat this process (download the newer source, make your changes, compile).

David Elizondo | LLBLGen Support Team