DateTime field is missing in generated INSERT

Posts   
 
    
horo
User
Posts: 41
Joined: 01-Sep-2005
# Posted on: 15-Aug-2006 13:54:57   

Hi to All,

Scenario : Adapter, NET 2.0

I add a new Entity with EntityCollection's AddNew(). (The entitycollection is a generated Detail property of the Master entity, using the generated default factory)

Detail entity has property X, which is DateTime, and it is initialized properly with the DateTime value provided by TypeDefaultValues, we use the DateTime.Now().

Examining the generated INSERT, it turned out, the in this case no parameter generated for the field X, which is a problem, because it is not nullable, so server side error occours.

If we "touch" the X property of the Detail Entity setting it to some value, the X parameter generated in INSERT.

What to do to always generate this parameter in case of new entity?

thx for answers

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 15-Aug-2006 15:29:27   

Hi,

The TypeDefaultValues class helps converting null fields into default .Net workable values. It does not serves instanciating fields with default values, which should be done in the table column specs in the first place.

Thus, even if your X property gives you a datetime.now() value, the fields behind has a null value. Furthermore, you should be able to see that value is updated each time you access it, so I don't think it's a good idea to set that value there.

Now, if you want to assign the property some default value in the code, there are many places to do that.

The most natural maybe to update the corresponding entity factory, making sure to place your code inside the usercode region so that it does not get overriden on next generations.

Alternatively, if you want to insert that value only in the last moment, you may activate the validator generation in your scenario and use your specific entity validator to make it set the date.

Playing with the entity code (user code regions /inherited/partial entity?) might be another solution, but I wouldn't recommand it since it is trickier due to the entity complex life cycle, and you have to remember that anything outside of user code region shouldn't be modified, unless by modifying the templates, which should also be kept for very specific needs.

Hope that helps

horo
User
Posts: 41
Joined: 01-Sep-2005
# Posted on: 16-Aug-2006 08:15:59   

Hi Jesse,

Thx for your answer. It helped.

horo