Generated query still has column which was deleted

Posts   
 
    
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 15-Sep-2009 01:20:58   

Version 2.5 Final - March 28th 2008

I just renamed a column and deleted another column, regenerated the code, recompiled, and I still get an error saying "Invalid column name" for both of the changed columns. What's happening is the old columns are still being added to the generated fetch query. I can't figure out how to make it stop referencing these old columns.

Any help would be greatly appreciated. I have never had this problem in many years of using LLBLGen.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Sep-2009 06:43:11   

Hi Aaron,

Couple of things:

  1. You said "I renamed column", "I deleted column". Where? (Database or LLBLGen Designer)

  2. If you renamed/deleted columns in DB, you have to "Refresh Catalog" in LLBLGen Desinger before regenerating code. You didn't mention this step.

  3. If you renamed column in DB and Refresh Catalog and then regenerated code, please double-check this:

3.1. The files aren't read-only in your file-system (commonly if you are using a source control).

3.2. You are generating code into the correct folder.

3.3. The entity have the same name as before.

David Elizondo | LLBLGen Support Team
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 15-Sep-2009 19:41:03   

daelmo wrote:

Hi Aaron,

Couple of things:

  1. You said "I renamed column", "I deleted column". Where? (Database or LLBLGen Designer)

  2. If you renamed/deleted columns in DB, you have to "Refresh Catalog" in LLBLGen Desinger before regenerating code. You didn't mention this step.

  3. If you renamed column in DB and Refresh Catalog and then regenerated code, please double-check this:

3.1. The files aren't read-only in your file-system (commonly if you are using a source control).

3.2. You are generating code into the correct folder.

3.3. The entity have the same name as before.

Yes, these are all very good questions. I did leave some steps out of what I did do.

  1. I did rename and delete the columns from the same database table.
  2. I did refresh the catalog and see the changes in the LLBLGen Designer. 3.1 The files are not read only in my file system and the newly generated files do show the changes. The renamed column is renamed as the field on the entity and the deleted column is not part of the entity. 3.3 The name of the entity has not changed, it is exactly the same as before.

I have also been searching my code to see if one of the two problem fields is being used some where but I can not find any use of them. I was referencing the fields in a asp.net GridView but I have removed these references.

Thank you for the response. Is there anything else I can check or look for?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 15-Sep-2009 21:15:15   

The next step is to generate to an empty folder to ensure that none of the previous version of the code can be interfering in any way...

Matt

tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 15-Sep-2009 21:28:36   

MTrinder wrote:

The next step is to generate to an empty folder to ensure that none of the previous version of the code can be interfering in any way...

Matt

Hello Matt,

I just made a backup of the previously generated code, then deleted it from the folder that I generate to, then regenerated new code, recompiled and still have the same problem.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 15-Sep-2009 21:47:36   

Are you getting the message when you try and compile the generated code - or when you use it in code...?

If it's in code could you post a stack trace so we can take a look?

Thanks

Matt

tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 15-Sep-2009 21:55:51   

MTrinder wrote:

Are you getting the message when you try and compile the generated code - or when you use it in code...?

If it's in code could you post a stack trace so we can take a look?

Thanks

Matt

The project compiles fine, it's when it's running that it dies with the error because the code is generating a query that the database can't execute because of the column difference.

The ComputerName column was renamed to HardwareName and the IsAdmin column was deleted from the table.

Here is the exception details.


SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException was unhandled by user code
  Message="An exception was caught during the execution of a retrieval query: Invalid column name 'ComputerName'.\r\nInvalid column name 'IsAdmin'.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception."
  Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20"
  RuntimeBuild="01222008"
  RuntimeVersion="2.5.0.0"
  QueryExecuted="\r\n\tQuery: SELECT [CDGEquipment].[dbo].[UserHardware].[HardwareID] AS [HardwareId], [CDGEquipment].[dbo].[UserHardware].[UserID] AS [UserId], [CDGEquipment].[dbo].[UserHardware].[Make], [CDGEquipment].[dbo].[UserHardware].[Model], [CDGEquipment].[dbo].[UserHardware].[MfgModel], [CDGEquipment].[dbo].[UserHardware].[ComputerName], [CDGEquipment].[dbo].[UserHardware].[SerialNumber], [CDGEquipment].[dbo].[UserHardware].[IsAdmin], [CDGEquipment].[dbo].[UserHardware].[RetiredDate] FROM [CDGEquipment].[dbo].[UserHardware]  WHERE ( ( [CDGEquipment].[dbo].[UserHardware].[UserID] = @UserId1))\r\n\tParameter: @UserId1 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 1.\r\n"
  StackTrace:
       at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior)
       at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFactory2 entityFactory, IEntityCollection2 collectionToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, Boolean allowDuplicates, IEntityFields2 fieldsUsedForQuery)
       at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize)
       at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize)
       at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket)
       at Wellsfargo.CDG.Equipment.AppServices.EquipmentManager.GetHardwares(Int32 userId, IEntityCollection2 results) in C:\Program Files\Projects\Equipment Manager\EquipmentManagerSln\Wellsfargo.CDG.Equipment.AppServices\EquipmentManager.cs:line 72
       at _Default.hardwareDS_PerformSelect(Object sender, PerformSelectEventArgs2 e) in c:\Program Files\Projects\Equipment Manager\EquipmentManagerSln\EquipmentManagerWebsite\Default.aspx.cs:line 336
       at SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSource2.OnPerformSelect(PerformSelectEventArgs2 eventArgs)
       at SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView2.ExecuteSelectEntityCollection(Int32 pageSize, Int32 pageNumber, DataSourceSelectArguments arguments)
       at SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView2.ExecuteSelect(DataSourceSelectArguments arguments)
       at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
       at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
       at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
       at System.Web.UI.WebControls.GridView.DataBind()
       at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
       at System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e)
       at System.Web.UI.WebControls.GridView.OnPreRender(EventArgs e)
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Sep-2009 06:20:27   

Did you see the change in the LLBLGen project (lgp)? For example, If you edit the entity, what is the source column name?

In other words, did the DB change get reflected in lgp? (maybe you are refresing catalog from wrong db)

David Elizondo | LLBLGen Support Team
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 16-Sep-2009 18:48:30   

daelmo wrote:

Did you see the change in the LLBLGen project (lgp)? For example, If you edit the entity, what is the source column name?

In other words, did the DB change get reflected in lgp? (maybe you are refresing catalog from wrong db)

Yes, the LLBLGen designer shows exactly as I would expect it to. The column that I renamed is shown as renamed and the column that I deleted does not show up at all.

See the attachment.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Sep-2009 06:01:49   

Wow. Weird indeed. So, lets summarize what we got at this point:

  1. Schema change: OK

  2. LLBLGen Designer change: OK

3. Generate to an empty folder and no read-only permission on the files: OK

  1. The mapping are there (on generated code) ? This is:
  2. Open the [TheDBSpecificGeneratedCodeFolder]\PersistenceInfoProvider.cs

  3. Look for a method like InitCdgEquipmentEntityMappings

  4. In there should be a line like:

base.AddElementFieldMapping( "CdgEquipmentEntity", "HardwareName", "HardwareName", ...
  • So, if you see ComputerName, something went wrong but I'm pretty sure this step will be ok.

  • If the mappings are ok then should be another problem. e.g.: Maybe you are referencing an old copy of the assembly into your Website (I saw you are fetching from a website). Steps to check this:

5.1. Clean and rebuild your website. OR 5.2. Re-add the project reference OR 5.3. Try to make a similar fetch in a consoleApp or testProject, to see whether the problem is the WebSite.

So, lets try 4 and 5 simple_smile

David Elizondo | LLBLGen Support Team
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 18-Sep-2009 00:25:48   

daelmo wrote:

Wow. Weird indeed. So, lets summarize what we got at this point:

  1. Schema change: OK

  2. LLBLGen Designer change: OK

3. Generate to an empty folder and no read-only permission on the files: OK

  1. The mapping are there (on generated code) ? This is:
  2. Open the [TheDBSpecificGeneratedCodeFolder]\PersistenceInfoProvider.cs

  3. Look for a method like InitCdgEquipmentEntityMappings

  4. In there should be a line like:

base.AddElementFieldMapping( "CdgEquipmentEntity", "HardwareName", "HardwareName", ...
  • So, if you see ComputerName, something went wrong but I'm pretty sure this step will be ok.

  • If the mappings are ok then should be another problem. e.g.: Maybe you are referencing an old copy of the assembly into your Website (I saw you are fetching from a website). Steps to check this:

5.1. Clean and rebuild your website. OR 5.2. Re-add the project reference OR 5.3. Try to make a similar fetch in a consoleApp or testProject, to see whether the problem is the WebSite.

So, lets try 4 and 5 simple_smile

So, before I received the your latest message I completely deleted everything, including the LLBLGen .lgp file, and created a new LLBLGen project, read the database from scratch and regenerated everything from scratch. This did solve the problem, the errors that I had went away.

So this did work but I don't like having an open ended problem like this. I really don't want to have to do this again. Fortunately this project was small and easy to rebuild but if I had a much bigger project with customizations it would have been a long process.

Having said that, I made a backup of the old project and code and am continuing to work on this problem.

  1. I think the method you are referring to in my code is called InitUserHardwareEntityMappings. This is the mapping method for the UserHardware table to fields.

Yes, like this:


base.AddElementFieldMapping( "UserHardwareEntity", "HardwareName", "HardwareName", false, (int)SqlDbType.VarChar, 50, 0, 0, false, "", null, typeof(System.String), 6 );

  1. Yes, I did all of these things before finally completely deleting everything and starting over.

Earlier on it was mentioned that I should try deleting all of the generated code and starting a code generation from scratch. I did this and it did not solve the problem. The problem was finally solved after deleting the .lgp project file as well. Does this point the problem back to the .lgp project file?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Sep-2009 05:39:10   

I dont think i was on lgp but who knows. At lest I can't reproduce it. If you attach the lgp we could test it.

David Elizondo | LLBLGen Support Team
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 18-Sep-2009 18:37:38   

daelmo wrote:

I dont think i was on lgp but who knows. At lest I can't reproduce it. If you attach the lgp we could test it.

OK the lgp file is attached. I don't know what else to do at this point but let it go until it happens again.

Please let me know if you find anything in the lgp file.

Thanks for all the help.

Attachments
Filename File size Added on Approval
Equipment Manager.lgp 36,775 18-Sep-2009 18:37.50 Approved
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Sep-2009 22:25:23   

Hi Aaron,

I can't reproduce the problem with your lgp file. I run sql templates to generate a DB scritpt, then I create the database, I generate code and make simple tests on that table: all is ok.

So, it must be something else. My guess is that it had to do with caching references or something weird in the that way. I'm sorry you became into this. Fortunately you found a workaround but you should re-test your old project, it is just fine here. Mabe if you create another test project that references the generated code?

Best regards.

David Elizondo | LLBLGen Support Team