Generated Code Contains references / files for deleted entities

Posts   
 
    
harmandj
User
Posts: 1
Joined: 01-Jul-2009
# Posted on: 01-Jul-2009 23:57:10   

Hi,

I have picked up a project that is nearing completion and has been created using LLBL Gen Pro. I am totally new to this technology.

A table has been deleted in the database (table name: DeliveryLocationGroups). Within the LLBL project the table is still in the entity list. I have done a catalog refresh which removed the entity from the list, there were no errors from doing this. I am using SQL Server 2008.

I selected to generate the code, the destination root folder is where the most recent generated code already exists. Target platform = .NET2.0 Language = c# Template Group = SelfServicing //Code is generated using LLBLGen Pro version: 2.6 // Code is generated on: 01 July 2009 22:32:27 // Code is generated using templates: SD.TemplateBindings.SharedTemplates.NET20 // Templates vendor: Solutions Design. // Templates version:

There were no errors from the code generation.

I Opened the project generated by LLBL in my development environment.

Build failed - DeliveryLocationGroupsFieldIndex could not be found. The DeliveryLocationGropsCollection class still existed which is where the errors were. I would have expected this file to have been removed. I deleted the file and built again. This time errors in the DeliveryLocationGroupsEntityBase class (another file I thought would have been removed). Again I deleted the offending file and built again. Error in the DeliveryLocationGroupsEntity class this time. (Deleted and built again). 2454 errors in various classes.

If I set the code generator to generate the code in a brand new folder, it compiles fine, but then when I try to build the rest of the application I get build errors due to methods which have been added to the generated code files no longer being present, so I can't really venture down this route.

Please can someone point me in the correct direction to solve this issue, I have looked for settings when generating the code but can't find anything obvious I am missing.

Thanks

David

rdhatch
User
Posts: 198
Joined: 03-Nov-2007
# Posted on: 02-Jul-2009 00:31:29   

Hi David -

This is expected behavior. LLBLGen's Designer will not delete files - otherwise it could be deleting some of your custom user code, if you've added code within the generated files.

Although you can add your custom code within the #USER CODE REGIONS# of the generated code - it is certainly not recommended.

Here's what I do, and it works well.

Now, Add a folder to your project for Custom Code. I usually call mine "!Custom Code". The exclamation mark simply keeps my Custom Code folder listed above all other [generated] folders.

Now, Place all your custom code into new files within the "!Custom Code" folder. These files are called Partial classes. This setup allows you to override any method in the Entities, and keep your custom code entirely separate from generated code. Also, you don't need a Partial class for every Entity - only for your Entities that have custom code.

Realize - I never add custom code to the generated files. Always use Partial classes - which reside within my "!Custom Code" folder.

So, I can literally delete all folders from my project - except my "!Custom Code" folder. When I regenerate - everything is very clean.

Hope this helps!

Ryan

PS. Here's what a Partial class (under the Custom Code folder) looks like:

Namespace YourDataObjects.EntityClasses

    Partial Public Class ItemDetailEntity
    ....
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Jul-2009 04:36:20   

You also could use the **CleanUpVsNetProjects **flag, at ProjectProperties/UserPreferences:

docs wrote:

**CleanUpVsNetProjects **When set to true, the VS.NET project file task performer will first remove all file references for files from an existing VS.NET project file, before adding the files generated. For VS.NET 2005 projects, it will remove all files generated by LLBLGen Pro, as these are marked with a Generator tag.

Just note this warning (what Ryan already mentioned):

Use with care as an old VS.NET project may contain references to files which aren't marked with LLBLGen Pro specific XML elements/attributes, so all file references are removed, which thus also means that references to files you've added yourself to the project are removed as well, which forces you to re-add the references to those files to the VS.NET project manually. Projects created for VS.NET 2005 and with LLBLGen Pro v2.0 or higher do have the files marked as LLBLGen Pro generated and it's safe to use this setting with these projects.

And again, LLBLGen wont delete any file. It just -if you want- will remove the file references and then add the valid files to the project. That means that the file of the removed entity is still in your file system but not in the project anymore.

more about Project Properties and User Preferences...

David Elizondo | LLBLGen Support Team