Print Page | Close Window

non null foreign keys

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2576
Printed Date: 07-Apr-2025 at 3:02am


Topic: non null foreign keys
Posted By: hueha
Subject: non null foreign keys
Date Posted: 22-Mar-2011 at 6:02am
I'm not sure if this is the same thing that this thread is talking about
http://www.ideablade.com/forum/forum_posts.asp?TID=2540&title=navigation-property-verification - http://www.ideablade.com/forum/forum_posts.asp?TID=2540&title=navigation-property-verification

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



Replies:
Posted By: smi-mark
Date 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.


Posted By: DenisK
Date 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.



Print Page | Close Window