Manager templates, Create() and inheritance

Posts   
 
    
Faldaani
User
Posts: 14
Joined: 18-Sep-2007
# Posted on: 19-Sep-2007 00:11:16   

Hello

Currently evaluating LLBLGen and as it looks now I'm probably going to buy it... there's something about taking a template and modifying it, generating code that does exactly what I want and then generating unit tests for the code I just generated that makes me feel happy inside =)

Anyway, I've run into something that is probably a newbie problem that would easily be resolved by actually buying LLBLGen and downloading the SDK and Template editing tool (?), but I have to get permission to buy it first, and I'm impatient.

I have a base entity called Part, with CustomPart and StandardPart (Yeah, I know, a standard part should be a part! ) that inherits from it. Works perfectly fine.

Part - Abstract: - ID int primary key - CategoryID int references Category entity - Bunch of other regular varchars

StandardPart - ID int primary key references Part.ID 1:1 - shipping int - bunch of varchars

CustomPart - ID int primary key references Part.ID 1:1

However, I've been modifying the Manager templates and have run into a problem with the Create method that is generated.

This is from EntityManagerBaseTemplate


<%
ArrayList writableFieldRelationPairs = GetWritableFieldRelationPairs(Entity);
ArrayList writableFields = FieldRelationPair.ToFieldList(writableFieldRelationPairs);
ArrayList minimalFieldRelationPairs = GetMinimalFieldRelationPairs(Entity);     
ArrayList minimalFields = FieldRelationPair.ToFieldList(minimalFieldRelationPairs);
%>
/// <summary>
/// Creates a full <c><%=ObjectName%>Entity</c>
/// </summary>
<%=BuildParamComments(writableFields)%>
/// <returns>A populated <c><%=ObjectName%>Entity</c>.</returns>        
public static <%=ObjectName%>Entity Create(<%=BuildFieldParameterList(writableFields)%>)

The writableFields variable (when generating the StandardPartManager) does not seem to contain the CategoryID or the varchars from Part, so the object that is created isn't really "full".

From what I've been able to see from looking at the template file with no color coding, the GetWritableFieldRelationPairs is a function included in the template, but thats about as far as it gets for me using notepad.

Was kind of hoping someone had experience with these templates and could point me in the right direction...

I guess it could be me configuring something in a weird way in the designer too, but the relation seems to work fine.

Walaa avatar
Walaa
Support Team
Posts: 14987
Joined: 21-Aug-2005
# Posted on: 19-Sep-2007 18:12:15   

From where have you got these manager templates? Which version are they? And whcih version of LLBLGen Pro are you using these templates with?

Faldaani
User
Posts: 14
Joined: 18-Sep-2007
# Posted on: 19-Sep-2007 20:21:57   

Walaa wrote:

From where have you got these manager templates? Which version are they? And whcih version of LLBLGen Pro are you using these templates with?

Oh, sorry.. forgot to mention that.

Its the latest version of templates from the SVN server (Found that one by digging through this forum). I have modified them so that they work for .NET 3.0 (basically added .NET 3.0 to supported types).

As for LLBLGen, its the latest version - downloaded yesterday, 2.5 i believe.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39774
Joined: 17-Aug-2003
# Posted on: 20-Sep-2007 11:27:16   

The templates aren't really supported by us, as they're written by a customer, though I think the problem is in line 1254, where the routine to get the writable fields is reading just the fields of the entity, but not the HierarchyFields, so it doesn't look at inherited fields.

I think that general concept will be a problem in more places in these templates if this isn't implemented here. (as it will likely also miss the inherited relations). The SDK comes with a reference manual for the object model this template is targeting, so you're not in the dark what's going on. You also don't need the manager templates to use LLBLGen Pro btw, though they can be a good start for people who want to dive into custom template authoring.

Frans Bouma | Lead developer LLBLGen Pro
Faldaani
User
Posts: 14
Joined: 18-Sep-2007
# Posted on: 20-Sep-2007 15:04:25   

Yeah, I know they aren't supported. Was just hoping that someone would have experience using/modifying them, since this is THE LLBLGen forum after all.

I know I don't have to use them, just that they fit my project perfectly. I'll probably get approval to buy in a week or two, but as I said - impatient =)

Anyway, thanks for the tip, I'll look into it.

worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 09-Nov-2007 08:16:11   

The manager templates consist of a whopping 3 templates (and a 4th one PrefectPathElementCollectionTemplate u can ignore). You do not need the template editor to modify the templates. It's just a glorified (buggy) text editor with some handy syntax highlighting.

Frans is right, I had the same problem when I started leveraging table inheritence. That was about the same time I decided to stop using the manager templates. They're pretty useless, just a bunch of helper methods for lazy coders really. I prefer managing my DataAccessAdapter instances and calling them directly. It's called "elegant coding". wink

I'm curious what you see in them? Besides a spot to plug in BL code...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39774
Joined: 17-Aug-2003
# Posted on: 09-Nov-2007 12:41:38   

worldspawn wrote:

The manager templates consist of a whopping 3 templates (and a 4th one PrefectPathElementCollectionTemplate u can ignore). You do not need the template editor to modify the templates. It's just a glorified (buggy) text editor with some handy syntax highlighting.

hey! It's not that buggy. simple_smile We fixed most of the glitches out there in the v2.5 release. It's not VS.NET, and the intellisense is not really great, but it does its job. wink

Frans is right, I had the same problem when I started leveraging table inheritence. That was about the same time I decided to stop using the manager templates. They're pretty useless, just a bunch of helper methods for lazy coders really. I prefer managing my DataAccessAdapter instances and calling them directly. It's called "elegant coding". wink

I'm curious what you see in them? Besides a spot to plug in BL code...

I think they're a good example what you can do with code generation, so it's not always best to simply adapt them, but it can be a great starting point for getting your own templates for the code you want to /have to write anyway. simple_smile After all, who wants to type in a lot of code if you can tell a program to do it for you, eh? wink

Frans Bouma | Lead developer LLBLGen Pro
Faldaani
User
Posts: 14
Joined: 18-Sep-2007
# Posted on: 09-Nov-2007 15:59:44   

Indeed.

I am no longer using them... good for getting the hang of LLBLGen though, and a good starting point for custom templates.