Interface templates

Posts   
 
    
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 20-Jul-2009 01:49:47   

Hello,

are there any inbuilt tasks to create interfaces for the entities (with only the fields)?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Jul-2009 02:34:03   

Hi Sam.,

At LLBLGenPro Designer, you can use Output specific settings. There you can specify additional interfaces for the entities. Is that what you are looking for?

David Elizondo | LLBLGen Support Team
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 20-Jul-2009 05:59:45   

Hi daelmo,

I was after a template&task. I've modified one I found elsewhere on the forums but I am having one problem.


////////////////////////////////////////////////////////////////////////////////////////////////////////
// This is generated code.
////////////////////////////////////////////////////////////////////////////////////////////////////////
// Code is generated using LLBLGen Pro version: <[LLBLGenVersion]>
// Code is generated on: <[Time]>
// Code is generated using templates: <[TemplateName]>
// Templates version: <[TemplateVersion]>
////////////////////////////////////////////////////////////////////////////////////////////////////////
using System.Collections.Generic;

namespace <[RootNamespace]>{
    public interface I<[CurrentEntityName]> <[ If IsSubType ]>
        : I<[ SuperTypeName ]> <[ EndIf]> { 
<[Foreach RelatedEntity OneToMany]><[If Not MappedFieldRelationIsHidden]>   <[ UserCodeRegion MappedFieldNameRelation "($VALUE)Attributes" ]>
    // __LLBLGENPRO_USER_CODE_REGION_START <[UserCodeRegionName]>
    // __LLBLGENPRO_USER_CODE_REGION_END<[ EndUserCodeRegion ]>
    IList<I<[RelatedEntityName]>> <[MappedFieldNameRelation ]>{ get; }
<[EndIf]><[NextForeach]>
<[Foreach RelatedEntity ManyToMany]><[If Not MappedFieldRelationIsHidden]>  <[ UserCodeRegion MappedFieldNameRelation "($VALUE)Attributes" ]>
    // __LLBLGENPRO_USER_CODE_REGION_START <[UserCodeRegionName]>
    // __LLBLGENPRO_USER_CODE_REGION_END<[ EndUserCodeRegion ]>
    IList<I<[RelatedEntityName]>> <[MappedFieldNameRelation]>{ get; }
<[EndIf]><[NextForeach]>
<[Foreach RelatedEntity ManyToOne]><[If Not MappedFieldRelationIsHidden]>   <[ UserCodeRegion MappedFieldNameRelation "($VALUE)Attributes" ]>
    // __LLBLGENPRO_USER_CODE_REGION_START <[UserCodeRegionName]>
    // __LLBLGENPRO_USER_CODE_REGION_END<[ EndUserCodeRegion ]>
    I<[RelatedEntityName]> <[MappedFieldNameRelation]>  { get; set; }
<[EndIf]><[NextForeach]>
<[Foreach RelatedEntity OneToOne]><[If Not MappedFieldRelationIsHidden]>    <[ UserCodeRegion MappedFieldNameRelation "($VALUE)Attributes" ]>
    // __LLBLGENPRO_USER_CODE_REGION_START <[UserCodeRegionName]>
    // __LLBLGENPRO_USER_CODE_REGION_END<[ EndUserCodeRegion ]>
    I<[RelatedEntityName]> <[MappedFieldNameRelation]> { get; set; }
<[EndIf]><[NextForeach]>
<[Foreach EntityField]> 
    // __LLBLGENPRO_USER_CODE_REGION_START <[UserCodeRegion EntityFieldName "($VALUE)Attributes"]>
    // __LLBLGENPRO_USER_CODE_REGION_END<[ EndUserCodeRegion ]>
    <[If IsPrimaryKey ]><[ If IsSubType ]>new <[EndIf]><[EndIf]><[If IsNullable]><[If IsValueType]><[TypeOfField]>?<[Else]><[TypeOfField]><[EndIf]><[Else]><[TypeOfField]><[EndIf]> <[EntityFieldName]> { get;<[If IsReadOnly ]><[Else]>set;<[EndIf]>}
<[NextForeach]> 
    }
}

This works fine mostly except for the last loop. For some reason the UserCodeRegion macro isn't working there. (With EntityFieldName). The output has no region name, eg:


// __LLBLGENPRO_USER_CODE_REGION_START 
    // __LLBLGENPRO_USER_CODE_REGION_END
    System.Boolean IsActive { get;set;}

The RelatedField loops have no problem creating a valid user code region it's just this EntityField loop that doesn't work.

Also, is there a (easy) way to output c# type aliases instead of CLR type names?

worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 20-Jul-2009 06:23:50   

disappointed This is turning out to be a bit of a waste of time. I dont use interfaces much so I made the assumption that (for example):

IUser UserUsingCreatedById

could be implemented as

UserEntity UserUsingCreatedById

but it can't... C# compiler is complaining its the wrong type... Seems stupid to me as we KNOW UserEntity implements IUser. Bit of a show stopper this one.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 20-Jul-2009 10:00:48   

I made the assumption that (for example):

IUser UserUsingCreatedById

could be implemented as

UserEntity UserUsingCreatedById

but it can't... C# compiler is complaining its the wrong type... Seems stupid to me as we KNOW UserEntity implements IUser. Bit of a show stopper this one.

The above lines of code doesn't really show where the problem is, please post the real C# code which doesn't compile.

worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 20-Jul-2009 10:19:32   

Hi Walaa,

This isn't really a llbl question, more like a basic C# language query. But if you like i have this interface member of IActivity:


IProject ProjectUsingProjectId  { get; set; }

and the on my ActivityEntity class (generated by LLBL) I have added IActivity to it's inheritence.


public virtual ProjectEntity ProjectUsingProjectId
{
//stuff
}

This results in:

D:\Projects\Shivam Client Portal\Main\Source\SCP v1.0\Shivam.SCP.DAL\EntityClasses\ActivityEntity.cs(35,23): error CS0738: 'Shivam.SCP.DAL.EntityClasses.ActivityEntity' does not implement interface member 'Shivam.SCP.DAL.IActivity.ProjectUsingProjectId'. 'Shivam.SCP.DAL.EntityClasses.ActivityEntity.ProjectUsingProjectId' cannot implement 'Shivam.SCP.DAL.IActivity.ProjectUsingProjectId' because it does not have the matching return type of 'Shivam.SCP.DAL.IProject'.

I was kind of hoping that seeing as ProjectEntity implements IProject I wouldn't have to implement the ProjectUsingProjectId interface member as "IProject". It seemed reasonable to me. I mean ProjectEntity can be implicity cast to IProject so... wtf..

Regarding my other query with UserCodeRegions I was doing something stupid. I for some reason wrote that one bit of the template expecting <[UserCodeRegion EntityFieldName "($VALUE)Attributes"]> to output the region name instead of having a seperate <[UserCodeRegionName]>. I didn't copy+paste properly or something.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 20-Jul-2009 10:42:53   

IProject ProjectUsingProjectId { get; set; }

Here you define a property of Type IProject. The question is where did you define this property? in which class?

And if you wanted the entity ti inherit from that interface, then you should define it as follows:

public virtual ProjectEntity IProject
{

}

And depending on the interface definistion, your entity should implement the interface since it inherits from it. i.e. it should define the implementation of all methods defined in the interface.

Regarding my other query with UserCodeRegions I was doing something stupid. I for some reason wrote that one bit of the template expecting <[UserCodeRegion EntityFieldName "($VALUE)Attributes"]> to output the region name instead of having a seperate <[UserCodeRegionName]>. I didn't copy+paste properly or something.

OK.

worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 21-Jul-2009 05:38:27   
IProject ProjectUsingProjectId { get; set; }

That is the property as it is defined on the IActivity interface.

my ActivityEntity implements IActivity. LLBL generates this property for me:

public virtual ProjectEntity ProjectUsingProjectId
{get{...}set{...}}

But unfortunately that is not accepted as an "implementation" of the property defined on the IActivity interface even though ProjectEntity implements IProject.

It doesn't make sense to me because if ProjectEntity implements IProject then for interface contract purposes ProjectEntity ProjectUsingProjectId and IProject ProjectUsingProjectId are one and the same.

Anyway, this is a language issue. Not an LLBL issue.