New Posts New Posts RSS Feed: non null foreign keys
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

non null foreign keys

 Post Reply Post Reply
Author
hueha View Drop Down
Newbie
Newbie


Joined: 23-Jul-2010
Posts: 38
Post Options Post Options   Quote hueha Quote  Post ReplyReply Direct Link To This Post Topic: non null foreign keys
    Posted: 22-Mar-2011 at 6:02am
I'm not sure if this is the same thing that this thread is talking about

But I'll explain my problem.  In the database I have a table let's say invoice and invoicedetail

InvoiceDetail has a foreign key to Invoice called InvoiceID.  Since I don't want any orphan InvoiceDetail the InvoiceID field is not nullable in the database.

Devforce is creating the the key as an int and adds 
[IbVal.RequiredValueVerifier( ErrorMessageResourceName="InvoiceDetail_InvoiceID")]
 [IbEm.ForeignKey("Invoice")]
 
The problem I get is that since the field is an int the default value is 0.  Then when I go to validate the entity it passes without any validation errors.  I'm assuming this is because the RequiredValueVerifier is only looking for a null.  Is there a way that I can tell devforce to treat the 0 as if it were a null?  I could write my own verifier and then set up a metadata class to do my own validation but then I would have to do that for every foreign key in my database.  

Hue
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 23-Mar-2011 at 6:42am
This is the same issue that I talked about in my thread. You need to perform validation on the navigation property, not the foreign key. So rather than InvoiceLine looking at InvoiceId, InvoiceLine needs to ensure that the Invoice navigation property is not a NullEntity.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 23-Mar-2011 at 10:55am
Thanks for your response, smi-mark.

I'm adding a feature request to see if we can have this "RequiredEntityVerifier" to be a part DevForce validation.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down