in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

How do you create a NOT NULL column in the database table?

Last post 6/29/2008 6:29 PM by Marc Greiner [DX-Squad]. 4 replies.
Page 1 of 1 (5 items)
Sort Posts:
Previous Next
  • 8/31/2007 2:14 PM

    How do you create a NOT NULL column in the database table?

    Is there an attribute to create a NOT NULL column on a persistent field (i.e. string type) ?

    Dan Arnold
  • 8/31/2007 2:49 PM In reply to

    Re: How do you create a NOT NULL column in the database table?

    Hi Dan ;

    No, it is not possible to create a not null column in a database table.
    There are certainly reasons for this (some af them can be read in past
    posts), but it would certainly be nice to be able to create a not nullable
    column with a default value.

    This might not work for every DB system, though.

    Please have a look at this post (there are some earlier ones about it also
    but the information is always the same) :

    http://community.devexpress.com//forums/p/55123/185711.aspx#185711

    Regards,
    Marc Greiner [DX-Squad]
  • 8/31/2007 3:08 PM In reply to

    Re: How do you create a NOT NULL column in the database table?

    XPO does not (currently) support forcing NOT NULL within thhe datbase directly.
     
    See article:
     
     
    I would agree with DevExpress that this is not an ideal way to enforce such a rule.
     
    Consider:
     
    If your rule is enforced within a business logic layer, a null value would either be corrected immediately and automatically, or a response to the user would be sent immediately.
     
    If the rule is enforced within the database, then an attempt to insert must be performed, then an exception must be caught, and then the same logic that could have corrected the issue in the first place would need to be applied (auto-correct or respond to user).
     
    If you really do need such a feature within the database, then the column(s) must be manually adjusted.
     
     
     
    <Dan Arnold> wrote in message news:193327@community.devexpress.com...

    Is there an attribute to create a NOT NULL column on a persistent field (i.e. string type) ?



    http://community.devexpress.com//forums/p/57255/193327.aspx#193327

    Trevor Westerdahl - DX Squad
    BLOG: http://trevorunlocked.blogspot.com/
  • 6/28/2008 11:12 AM In reply to

    Re: How do you create a NOT NULL column in the database table?

    Almost every other ORM I have used including Genome, NHibernate, Xtensive DataObjects.Net ... allow definition of NOT NULL fields.

    If a certain database does not support it, then just ignore the NOTNULL attribute.

    This could easily be documented as an attriibute that is really just a hint, and that whether it has an efffect that depends on the backing store.

    Why is it that other ORMS that support multiple backends are able to pull this off? And DevExpress is Not?

    I'm hoping this issue gets re-evaulated in the future, maybe by hte XAF team, and changed.

     

    Thanks,

    Dan

    Dan Arnold
    Filed under: ,
  • 6/29/2008 6:29 PM In reply to

    Re: How do you create a NOT NULL column in the database table?

    Hi Dan,

    Just out of curiosity, why would you need to set a DB-field as not nullable? What would be a good reason to do so?

    One cannot dissociate the "Not Nullable" from a "Default Value". If the field is not nullable, it has to have a default value, or else it will be hard/impossible to keep backward compatibility of the application.

    In the process of maintaining an application, new object properties (and thus DB-fields) get created, others get deprecated and disappear from the XPObject, thus not being referenced in the automatically generated SQLs.

    XPO will not delete deprecated fields nor change the field type automatically, varchar to int, for example, althougth there is a discussion about this point.

    There are some advantages to work with not nuallable fields, but I haven't tested whether it is noticable.
    Not nullable fields do not require an extra hidden bit field telling if the value is null or not, creating slightly smaller DBs and faster indexes. The same is true for .NET nullable types, which are structures with a hidden boolean field.
    Is this the reason why you need to have not nullable fields?

    Regards,
    Marc Greiner [DX-Squad]
Page 1 of 1 (5 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED