This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have several tables with many fields, upwards of 50. In the SQL database 90% of these fields are set to be non-nullable, and have a default value defined. However, when I update my entities from the database, is sets the non-nullable value for the properties, but does not consider the default values, hence if I create a new instance of an entity class, and only complete say 10 or 20 of the parameters, the IsValid returns false, because all the non-nullable fields have not been given a value. For me to add a default value in code everytime I create a new record would be a nightmare. It seems to me the Update from Source can reteive so much information from the database, that is seems an oversight not to retrieve the default value also. Or am I making a complete ass of myself because it does and I just can't find it? ;-) PS. I did search through other posts but could not find this question / answer. |
|
|
No, you're not missing anything -- we don't currently retrieve default values. It's an interesting idea though and we'll definitely take a look at it, but we'd have to assess the effort involved and the implications for compatibility and for the complexity of the .lsmodel file. If you're working in C#, a workaround is to add a constructor in the partial class and initialise the non-nullable field values there: partial class WonderEntity { (This trick doesn't work in VB because, for technical reasons, in VB the designer generates a constructor as part of the generated code, so you can't add one in the partial class.) Obviously this still requires per-column hand coding, which I realise would be pretty intimidating for 50+ columns times N tables, but at least it saves you having to remember to set the default values every time you create a record. |
|
|
Hi Ivan, We are using C# as our development language, so I tried your suggestion of creating a constructor class to preset the values. I set all the Int values to be 0 and all the strings to be "" (an empty string). When a new instance of the entity is created, it has correctly taken all these values, however, when I come to check the nstance prior to saving, it still reports all the strings as not valid, i.e. it indicates that I cannot have an empty string. This is obviously a LS thing, as SQL is quite happy with an empty string being a not null value. I don;t want to jeapardise the integrity of the data by allowing nulls in the data, and relying on the entity constructor to set a default value. As there are other applications that access this data, and it will be while before they are all converted to using LS. Do you have any other suggestions I can try?
|
|
|
Hi MarkLFT, You can always edit the Fields.vm template to default the values for you. That is how I got around the same problem. #if ($field.DataType == "String")
private $Translator.TranslateType($field.DataType, $field.AllowNulls) _$Inflector.CamelCase($field) = ""; #else private $Translator.TranslateType($field.DataType, $field.AllowNulls) _$Inflector.CamelCase($field); #end But please if you do this your on your own.
Kind regards, Johan J v Rensburg
|
|
|
Hi Johan, Thanks for the advice, however, I must say that I really do not want to go down the path of modifying templates. Creating partial classes etc. I am happy to do, but beyond that, I definitely do not want to go. I tried a similar approach with another tool a little while ago, and now I am basically stuck on that version of the tool, unless I want to recreate all the changes I made to the templates in the newer version. Thanks anyway. Mark
|
|
|
Set AllowEmptyString = true on your presence validations. A presence validation usually means "there has to be a value here," i.e. from the user's point of view they have to enter something, rather than the technical concept of "it's not allowed to be null." AllowEmptyString tells LightSpeed to accept the empty string as a 'populated' value. |
|
|
Hi Ivan That worked a treat, thanks. My only observation is, that whilst that option is mentioned in the documentation, it took 30 minutes of searching through property screens, with no joy, and searching forums for information on where to find set this property value. Thanks Mark |
|