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
|
Hi everybody! Is it possible to have Nullable fields for entities generated by LightSpeed for NOT NULL columns of source table? We really need it because we don't want to have any default value (i.e. zero) - user have to enter data by hand otherwise validation should show an error that value has not been set and the field is still empty. In our case 0(zero) value for int fields is acceptable value and cannot be used as a flag showing that value is not valid. Setting these fields as NOT NULL in the database is not acceptable for us. Is there any workaround to achieve it? |
|
|
Hi, If I understand correctly you want the entity property to be nullable while the database column is non nullable? This is fine to specify in your model (although the model will always be out of sync with the database of course) by simply setting the IsNullable property on each entity property as required. When you create a new entity you will then have null's assigned to those properties and can validate on them. You can then update the properties after validation back to defaults so they will insert into the database. Of course this is only going to work when you are initially creating the entity - is that what you are after?
|
|
|
Yes, you understand me correctly. Thanks for the answer. Your suggestion is fine for a project with small number of tables and fields. We are working with database with more than 100 tables in it. Some tables have about 20 fields for data entered by user. These fields are not nullable in the database because they are mandatory and should not have a default value. The project still growing - it means changes in the database and updates of the model. With the approach you suggested we will get a headache every time when updating a model from database (everybody in the team should keep in mind tons of fields that have to be nullable). It would be good for us to use an attribute or a property in the model to instruct generator that specific property of class have to be generated as nullable type. But the attribute/property should not conflict with the schema of the database - just instruction for the generator. Do you have any suggestions/solutions for it? |
|
|
You are always going to have to make the Nullable changes manually if you are using the designer so if you want to avoid issues with re-generation you can switch the generation option for these fields to None and then define those fields and properties in a partial class manually. This will mean you only incur a one time cost of having to define all of these.
|
|
|
This is not what we need. This is still a kind of headache for us. Anyway thank you. |
|
|
+1 for a viable work around to this issue. We are having problems with some third party controls caused by the Empty Guids returned from non nullable fields in new records. It would be nice to have a global override for this, perhaps done in the same manner as the Naming Strategy. |
|