Changing table names

Posts   
 
    
Alvaro
User
Posts: 52
Joined: 01-Jun-2004
# Posted on: 11-Nov-2004 12:58:49   

Hi,

I've observed that the designer recognizes when a table or field had its name changed and retains the previous name as the new entity or property name.

For example if I had a table called MyTable with a field MyTableId I would get MyTableEntity with a MyTableId property. Then if the table name was changed to AnotherTable with a field AnotherTableId, the entity would remain the same.

Although I can see why this design decision was taken, it just happens that we always want our entities to be named exactly like the underlying tables. I know that the entity name can be changed easily in the designer. But since we are a team of 10 or 12 people sometimes inconsistencies arise and we forget to do it.

So basically what I'd like to see is an option in the designer to keep entity names synched with their underlying table names.

Maybe there is already an option to do this but I missed it?

Thanks! álvaro.-

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 11-Nov-2004 13:08:52   

This is on the todo list and will be implemented as a setting in the next designer update, which development starts later this month simple_smile

Frans Bouma | Lead developer LLBLGen Pro
wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 11-Nov-2004 13:46:52   

hmmm, Otis how do you know what fields to match - if their names have changed? Because i could rename one field and add 2 more fields that are identical to the renamed field except for the name.

Same question for tablenames....Is this not dangerous? The margin for Error seems very great!

Alvaro
User
Posts: 52
Joined: 01-Jun-2004
# Posted on: 11-Nov-2004 14:08:14   

It's great that you already had this on the to-do list! Always one step ahead of us!

You know, I kept thinking a little bit about this, and I think that in the particular case of relationship names that were changed manually in the designer, it would be nice to have a warning on either case (automatic synch or not).

Basically let's say that you had a table with four relationships to another table, which the designer names by default like Relationship, Relationship, Relationship, Relationship__.

If I took the time to manually rename them to something meaningful, I wouldn't like them to be automatically renamed to AnotherRel, AnotherRel, AnotherRel, AnotherRel__ because the field name changed.

Just thinking out loud. Cheers álvaro.-

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 11-Nov-2004 18:39:34   

wayne wrote:

hmmm, Otis how do you know what fields to match - if their names have changed? Because i could rename one field and add 2 more fields that are identical to the renamed field except for the name.

It checks the names on the same ordinal first. If these don't match, it will check the types. If these are the same, it will conclude it's a rename.

Same question for tablenames....Is this not dangerous? The margin for Error seems very great!

No it's fairly safe simple_smile But indeed, it can make mistakes. That's why I'll add an editor for this to fix mapping issues. simple_smile

Alvaro wrote:

It's great that you already had this on the to-do list! Always one step ahead of us!

Heh, you weren't the first who asked it wink

You know, I kept thinking a little bit about this, and I think that in the particular case of relationship names that were changed manually in the designer, it would be nice to have a warning on either case (automatic synch or not).

Basically let's say that you had a table with four relationships to another table, which the designer names by default like Relationship, Relationship, Relationship, Relationship__.

If I took the time to manually rename them to something meaningful, I wouldn't like them to be automatically renamed to AnotherRel, AnotherRel, AnotherRel, AnotherRel__ because the field name changed.

I agree, for these fields mapped on relations it's not obvious to just re-gen the names and throw away the current names. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
dwowens
User
Posts: 12
Joined: 14-Dec-2006
# Posted on: 26-Apr-2007 21:37:49   

Was this feature ever added? I currently have exactly this problem multiplied by several tables and many fields... and I'm worried I will miss some if I try to rename them each individually... not to mention all the many relationship-based names that should also be renamed.

I tried setting ManuallySelectRenamedTargetsAfterRefresh to true, but, as its description explains, this setting is ignored if you use unattended refresh. This confuses me, because if I use regular refresh, don't I lose all my configuration work anyhow because it starts from scratch? Which would mean that the setting doesn't have any effect anyhow. So, perhaps I'm misunderstanding something fundamental.

I tried setting SyncMappedElementNamesAfterRefresh... which sounded like it might change the field names to match the DB, but I got an error:

(version: 2.0.0.0 Final released on December 6th, 2006 DB: Sql Server 2005)

I got: A fatal exception occured during project refresh.

An error occured during the project refresh and the loaded project data is now unstable. LLBLGen Pro has silently unloaded the project data. It has saved the project before the catalog refresh started so you didn't lose any work. The project has been unloaded to prevent you from... etc etc etc.

When I ask to see the full exception information I get:

Message: Index and length must refer to a location within the string. Parameter name: length

Stack trace: -----[Core exception]-------------------- at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) at SD.LLBLGen.Pro.ApplicationCore.GeneralUtils.MakeCLSCompliantName(String nameToConvert, Boolean capitalizeFirstCharacter, Boolean makeElementNamePascalCasing, Boolean removeUnderscoresFromElementName) at SD.LLBLGen.Pro.ApplicationCore.CatalogRefresher.PostRefreshFixUpsEntities(ArrayList entitiesMigrated, LogNode entitiesRootNode) at SD.LLBLGen.Pro.ApplicationCore.CatalogRefresher.MigrateEntities() at SD.LLBLGen.Pro.ApplicationCore.CatalogRefresher.MigrateProjectToNewCatalog(Boolean isUnattended, SelectTargetsForOrphanedElementsCallBack targetSelectCallBack) at SD.LLBLGen.Pro.Gui.Forms.MainWindow.RefreshCatalogs(Boolean unattended, Hashtable catalogsToRefresh) at SD.LLBLGen.Pro.Gui.Forms.MainWindow.OnProjectExplorerCatalogRefreshClicked(Object sender, CatalogRefreshEventArgs e) at SD.LLBLGen.Pro.Gui.Forms.ProjectExplorer._menuItemCatalogRefreshUnattended_Click(Object sender, EventArgs e) at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Source: mscorlib

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 26-Apr-2007 22:27:38   

This last issue which caused the crash has been fixed lately, please update your designer to the latest build. It might be your database contains illegal names though. (like names with solely illegal chars like space, $, - etc. ) Please confirm if the latest build fixes it for you or not.

About the unattended refresh and the manual select dialog: an unattended refresh is unattended, which means: no popups whatsoever. So in an unattended refresh, any orphaned entities (their target isn't found after the refresh) are simply unmapped and thus deleted from the project.

Frans Bouma | Lead developer LLBLGen Pro
NickD
User
Posts: 224
Joined: 31-Jan-2005
# Posted on: 28-Apr-2007 00:30:19   

One of my colleagues misspelled a table in our database (stu_acheivement) and I changed it in the designed, only to discover that upon database refresh, it matches the name for me and sets it back. Most of the time this is a good thing, except in this case.

This is going to be one of those requests that all of Software Engineers hate, but I'm going to ask it anyway.

Could there be a flag to not rename tables or columns on a entity by entity basis?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Apr-2007 05:53:06   

Hi Nick, Copied from LLBLGenPro Help - Using the designer - Preferences and Project properties:

ManuallySelectRenamedTargetsAfterRefresh When set to true, (default is false) LLBLGen Pro will show you a dialog in which you can select the targets for entities for which the catalog refresher has detected that the targets aren't present in the new catalog, and are probably renamed. Overruled by an unattended refresh, in which case the catalog refresher will use the default: false.

**SyncMappedElementNamesAfterRefresh **When set to true, LLBLGen Pro will rename any entity, field mapped on relation, typed view, entity field and typed view field if the name of the element they're mapped on has changed, for example a table field is renamed. Setting this option to true can break your own code, so use this option with care. Default is false.

David Elizondo | LLBLGen Support Team
sunnyman
User
Posts: 51
Joined: 21-Feb-2007
# Posted on: 08-Jun-2007 13:45:06   

Hi,

After creating project from SQL Server DB, we need to change the generated code table names to simplify the developer’s life, using specific rules. I already create the code necessary to do this from .lgp file but I need to confirm it is a correct way and have no problem, for example Lazy Loading entities names and other compound naming (from entities names) will be correct

        Dim pro As ApplicationCore.Project
        Dim entity As ApplicationCore.Entities.EntityDefinition

        pro = ApplicationCore.Project.Load("C:\project.lgp")

        For Each entity In pro.Entities
            entity.Name = "PREFIX_" & entity.Name
        Next

        pro.Save()
sunnyman
User
Posts: 51
Joined: 21-Feb-2007
# Posted on: 08-Jun-2007 13:45:16   

Hi,

After creating project from SQL Server DB, we need to change the generated code table names to simplify the developer’s life, using specific rules. I already create the code necessary to do this from .lgp file but I need to confirm it is a correct way and have no problem, for example Lazy Loading entities names and other compound naming (from entities names) will be correct

        Dim pro As ApplicationCore.Project
        Dim entity As ApplicationCore.Entities.EntityDefinition

        pro = ApplicationCore.Project.Load("C:\project.lgp")

        For Each entity In pro.Entities
            entity.Name = "PREFIX_" & entity.Name
        Next

        pro.Save()

Do i need anyother action to get this worked? or just open the file and regenerate the code?

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-Jun-2007 15:43:28   

Although this would violate MS guidelines for code, I'd suppose this will work.

(Edit) Note: Next time please post a new thread rather than using an old thread. Guidelines: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7721

sunnyman
User
Posts: 51
Joined: 21-Feb-2007
# Posted on: 08-Jun-2007 19:36:06   

Hi,

Thanks to refer to GuideLines for asking question simple_smile , BTW,what do u mean by "violate MS guidelines for code" ?

Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Jun-2007 12:59:13   

I think Walaa is talking about naming conventions of microsoft coding guidelines. "http://msdn2.microsoft.com/en-us/library/x2dbyw72(VS.71).aspx"

David Elizondo | LLBLGen Support Team