PredicateFactory and SortFactory

Posts   
 
    
NewMind
User
Posts: 9
Joined: 27-Aug-2012
# Posted on: 27-Aug-2012 04:50:12   

I just upgraded from 1.0 to 3.5 and found there is no way to generate the PredicateFacotory and SortFactory.

I have hundreds of lines of codes that use the old pre mentioned factory classes.

1) Is there ANY way to generate these factory classes in 3.5? 2) If there is, what is the benefits gained from updating all of these lines of code to use the new xFields classes?

Thanks Daniel

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 27-Aug-2012 10:43:15   

NewMind wrote:

I just upgraded from 1.0 to 3.5 and found there is no way to generate the PredicateFacotory and SortFactory.

I have hundreds of lines of codes that use the old pre mentioned factory classes.

1) Is there ANY way to generate these factory classes in 3.5?

If you really must, you can: you can re-use the templates in v3.5, by adding a TDL executing task (llblgen pro templates are written in the TDL template language) to the preset you want to use and then point it to the template you copied from v1.0. It's best to store the template in a folder you specify as 'additional templates folder' in the project properties.

Please see the SDK for details: http://www.llblgen.com/documentation/3.5/SDK/hh_start.htm . If you get stuck with getting them to work, please let us know.

They've been marked deprecated since v2.0 and have been removed in v3.0. The main reason was that due to the large number of overloads they created, it could seriously slow down intellisense, plus they're not necessary anymore as in v2.0 we introduced operator overloading (e.g. you can create a fieldcomparevalue predicate by using e.g. CustomerFields.CompanyName=="SolutionsDesign" ), and in v3.5 we introduced queryspec which comes with extension methods for easier predicate creation if you don't want to use linq.

2) If there is, what is the benefits gained from updating all of these lines of code to use the new xFields classes?

Compatibilty with our API, and less code being generated. If your project is large, e.g. 400+ entities, the factory classes were a burden for intellisense. The same goes for the ResultsetFields class. Since v2.0 this class has lost its overloaded DefineField methods as well, as it could lead to a massive number of overloads if entities were big. We added a DefineField(field.. ) overload which is simple and doesn't have the same problems.

Predicates are easier to create now. If you're not using the operator overloads, you can also use the queryspec based extension methods, e.g.: (CustomerFields.City.IsNotNull().And(CustomerFields.Country=="USA"))

it's more readable, less code, and doesn't need a massive factory. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
NewMind
User
Posts: 9
Joined: 27-Aug-2012
# Posted on: 27-Aug-2012 17:03:28   

Do you have any article that you could point me to that details the steps to create the template to generate the factory classes? The Help link just give an overview of the TDL but not specific steps to take to get the factory classes back.

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 27-Aug-2012 19:15:15   

First of all, the removal of these two factories is by far the biggest change we made in the history of llblgen. In v3 we removed them, as we kept them disabled for so long in v2. You move from v1 to v3.5 so you make a big step, similar to moving from an asp.net 1 to asp.net MVC 4 application.

You can keep the v1 factories in your project btw, they still should be there, but of course if you change entities you want them to be updated.

Please take the following steps. (I assume you're using adapter, you haven't specified this. For selfservicing, it's almost the same, you just have to alter a different preset).

  • in the folder on disk where your llblgenproj file is located, create a folder: AdditionalTemplates
  • Copy into this folder the predicatefactoryadapter.template and the sortclausefactoryadapter.template. They're in <v1 installation folder>\SharedTemplates\C#
  • load your project in v3.5
  • in Project settings, go to General , then set the Additional Templates folder to '.\AdditionalTemplates' (without the quotes)
  • We're now going to add a template binding for the two templates. Go to: Window -> Show Windows Bindings Viewer.
  • Click the 'New...' button at the right. A dialog pops up.
  • Specify for Name: FactoryBindings
  • Click the [...] button next to file name and save the file in the AdditionalTemplates folder you created in step 1. Give it a name: 'FactoryBindings'
  • Click 'Save and close'. The dialog closes and your template bindings file is now created, and selected, but it's empty.
  • Click 'Edit as XML'. This is faster, as I've prepared the contents for you below.
  • Replace the contents of the file with the following:

<?xml version="1.0" encoding="utf-8"?>
<templateBindings  name="FactoryBindings for migration" description="" precedenceLevel="10" xmlns="http://sd/llblgen/pro/templateBindingsDefinition.xsd">
    <supportedPlatforms>
        <platform name=".NET 2.0" />
        <platform name=".NET 3.0" />
        <platform name=".NET 3.5" />
        <platform name=".NET 4.0" />
    </supportedPlatforms>
    <supportedFrameworks>
        <framework name="LLBLGen Pro Runtime Framework" />
    </supportedFrameworks>
    <supportedDrivers />
    <language name="C#">
        <templateBinding templateID="SD_PredicateFactory" filename="predicatefactoryadapter.template" templateLanguage="TDL" />
        <templateBinding templateID="SD_SortClauseFactory" filename="sortClauseFactoryAdapter.template" templateLanguage="TDL" />
    </language>
</templateBindings>

  • press cntrl-shift-S to save the template bindings file.
  • click the green refresh button in the tool bar (or use Tools -> Refresh code generation meta data). The template bindings for 'FactoryBindings for migration' are now updated.

All set for the last step: adding the tasks.

  • Press F7 and click 'Advanced' in the code generation dialog which pops up
  • On tab 2, verify that your template bindings file is visible under 'found template bindings'
  • On tab 3, select your preset. I presumed you're using adapter, so e.g. you select SD.Presets.Adapter.General2010. If you need/want to use another, no worries, the next step is fairly similar for all.

The following steps can also be done in XML, by editing the preset file or a copy of it. The steps below are using the UI in the designer.

  • In the run queue, you'll see all tasks the code generator engine will execute. We'll add 2 more, one for the predicate factory and one for the sort clause factory. Scroll down to the SD.Tasks.Generic.EntityFactoryClassesGenerator task. Select it. Then click 'Add tasks' at the right
  • In the Add task dialog, check the checkbox in front of 'SD.Tasks.Base.ConsumeTDLTemplate' (it's at the bottom), then click OK. It is inserted before the SD.Tasks.Generic.EntityFactoryClassesGenerator task.
  • Click the inserted task in the tree. In the 'selected task' information at the bottom, specify for display name 'Generate predicate factory'.
  • Click the 'tasks performer parameters' tab. For destinationFolder, specify: [dbgenericSubFolder]\FactoryClasses For filenameFormat, specify: PredicateFactory.[extension] For templateID, specify SD_PredicateFactory

Repeat the last 4 steps for the sortclause factory task as well. For the sortclause factory, you specify for task parameters: For destinationFolder, specify: [dbgenericSubFolder]\FactoryClasses For filenameFormat, specify: SortClauseFactory.[extension] For templateID, specify SD_SortClauseFactory

  • Click 'Save as' to save the preset. If you have specified an additional tasks folder in the project settings, you can save it there, otherwise simply save it in the llblgen pro folder as suggested by the dialog.

  • Run the generator by clicking 'start generator' at the bottom.

This should give you the 2 factories generated in the vs.net project and added to the vs.net project.

Frans Bouma | Lead developer LLBLGen Pro
NewMind
User
Posts: 9
Joined: 27-Aug-2012
# Posted on: 27-Aug-2012 23:53:08   

That did the trick!!!!!

THANK YOU THANK YOU THANK YOU

Daniel

NewMind
User
Posts: 9
Joined: 27-Aug-2012
# Posted on: 02-Sep-2012 23:36:14   

I went ahead and bit the bullet and updated my code to no longer use the PredicateFactory. However now that I have updated all of my code and removed all of my references I get the following error:

Could not load type 'xx.xx.FactoryClasses.PredicateFactory' from assembly...

I have verified I am no longer making any calls to or 'using' references to PredicateFactory and have the latest dlls in my bin folder

Any suggestions?

Thanks Daniel

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 03-Sep-2012 08:18:45   

Is this a webapp? If so, make sure the temp folders of ASP.NET in the microsoft.net folder in 'Windows' are empty. Also, it might be you're still referencing the old generated code. (although it's odd you don't use the factory anymore and it still refers to it... )

Frans Bouma | Lead developer LLBLGen Pro
NewMind
User
Posts: 9
Joined: 27-Aug-2012
# Posted on: 04-Sep-2012 22:38:04   

I found an old reference to a dll in a separate TFS branch causing the issue.

Thanks for the response and tips!

Daniel