Lenght of columns in generated code is not following length of referenced table for views

Posts   
 
    
kjaps
User
Posts: 2
Joined: 16-Nov-2020
# Posted on: 16-Nov-2020 13:22:20   

LLBLGen Pro 5.1.2 SQL Server 2019

I have a rather strange issue. We have generated the code on one database for years. Now we are moving towards another sourcedatabase. Both instanses are SQL Server 2019, and the schema is the same in both environment (as far as we can tell). When generating code with the new SQL Server as source, the Max-Lenght of some of the fields particularly in views changes. Even when the lenght of the column in the table the view is querying has not changed. I find this very strange.

An example:

Table: OppgaveAktivitet

Column Lenght
ArbeidsflytID nvarchar(100)
OppgaveID nvarchar(100)

...

View: K2OppgaveListe

alter view dbo.K2OppgaveList
as

select a.ArbeidsflytID, a.OppgaveID from dbo.OppgaveAktivitet

In our current environment the generated code for this view is created with 100 as the Max-Length of the field, but in our new sql server this columns is now changed to 50 for some reason. This was just a few of the fields that this is happening with. Multiple view-fields has this strange behaviour that they are not following the lenght of the column in the table the view is selecting from.

Attachments
Filename File size Added on Approval
Skjermbilde 2020-11-16 132353.png 362,393 16-Nov-2020 13:24.25 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 16-Nov-2020 16:40:18   

If this only occurs on views, it might be the view's meta data is outdated. This might sound silly but if you create a view, the meta data of the columns is stored, but if you then change the table(s) the view is based on, the metadata of the view isn't updated by sqlserver.

So if you open the view in a create script in SSMS, then drop/recreate the view using the create script, it's likely the view's metadata will reflect the real meta-data of the tables.

Frans Bouma | Lead developer LLBLGen Pro
kjaps
User
Posts: 2
Joined: 16-Nov-2020
# Posted on: 20-Nov-2020 16:10:03   

Thank you Otis. You were quite right. When dropping and recreating the views LLBLGen Pro generated correct lenght in the view entities.