Hello,
we have the problem that the generated VB.Net classes are read only for the primary key field "ID".
We can change the readonly bit within the ui and then the generated code will work but every time we regenerate the Model from database the ID-field is read only again.
This is very annoying.
Can you please help us.
Thanks in advance!
Generate primary keys for vb.net
Re: Generate primary keys for vb.net
In most cases, we don't generate the code for a setter of properties that correspond to the autoincrement fields due to the fact that the key value is generated in the database and assigned directly to the field, upon which the primary key property is built (JIC: it is not completely applicable to MS SQL Server, because it has mode allows you to insert data in such columns). Thus, these properties are "Read Only".
However, if you change it and don't select the "Recreate model" check box in the Update From Database Wizard, your model will not be cleared and rebuilt from the scratch. And, if the properties of the column (ID), which corresponds to the entity key (ID) of your class, have not been changed in the database, the entity key "ID" will remain unchanged in the model.
However, if you change it and don't select the "Recreate model" check box in the Update From Database Wizard, your model will not be cleared and rebuilt from the scratch. And, if the properties of the column (ID), which corresponds to the entity key (ID) of your class, have not been changed in the database, the entity key "ID" will remain unchanged in the model.
Re: Generate primary keys for vb.net
Thanks!
but I think I forgot to mention that the generated code isn't even compileable.
I can understand why the setter is not generated but then the prototype of the ID-Property is wrong
There is no ReadOnly-Attribute in the column definition and VB.net needs other than c#.net the ReadOnly declaration in it's prototypes. Otherwise the setters are strictly required and vb.net woun't compile.
Because of our starting rollout of linqConnector to all our projects we would have to correct the readonly bit for all tables on all our projects by hand.
Nothing I'm looking forward to at 200+ tables
but I think I forgot to mention that the generated code isn't even compileable.
I can understand why the setter is not generated but then the prototype of the ID-Property is wrong
Code: Select all
''' <summary>
''' There are no comments for Id in the schema.
''' </summary>
<Column(Name := "id", Storage := "_Id", AutoSync := AutoSync.OnInsert, CanBeNull := false, DbType := "INT(10) NOT NULL AUTO_INCREMENT", IsDbGenerated := true, IsPrimaryKey := true)> _
Public Property Id As Integer
Get
Return Me._Id
End Get
End Property
Because of our starting rollout of linqConnector to all our projects we would have to correct the readonly bit for all tables on all our projects by hand.
Nothing I'm looking forward to at 200+ tables
Re: Generate primary keys for vb.net
Thank you for the report. We will change the behaviour of the code generation for autoincrement properties in VB.Net. This changed behaviour will be available in the next build of LinqConnect. We will post here when it is available.
As a workaround, you could try performing the following:
- open used template in the Model Explorer (to make the template available for editing, copy it to the Model Folder - 'Copy to Model Folder' by right-click on the template in the Model Explorer);
- find the line in the Method GenerateProperty()
you should replace it with
- save changes and re-generate the code.
Please notify us about the results.
As a workaround, you could try performing the following:
- open used template in the Model Explorer (to make the template available for editing, copy it to the Model Folder - 'Copy to Model Folder' by right-click on the template in the Model Explorer);
- find the line in the Method GenerateProperty()
Code: Select all
<#= propAccess #><#= propInheritanceModifier #> Property <#= propName #> As <#= propType #>
Code: Select all
<#= propAccess #><#= propInheritanceModifier #><#= Iif(prop.ReadOnly, " ReadOnly", "") #> Property <#= propName #> As <#= propType #>
Please notify us about the results.
Re: Generate primary keys for vb.net
Thanks for your Help!
The workaround seems to work in a little test. So lets deploy and see if it works
Thanks again!
The workaround seems to work in a little test. So lets deploy and see if it works
Thanks again!
Re: Generate primary keys for vb.net
New build of LinqConnect 4.0.45 is available for download now!
It can be downloaded from http://www.devart.com/linqconnect/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=31&t=24531
It can be downloaded from http://www.devart.com/linqconnect/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=31&t=24531