Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Header and Detail table check constraint
 

Pages: 1
LLBLGen Pro Runtime Framework
Header and Detail table check constraint
Page:1/1 

  Print all messages in this thread  
Poster Message
tetris
User



Location:

Joined on:
05-Feb-2008 19:32:39
Posted:
3 posts
# Posted on: 05-Feb-2008 19:39:25.  
Hello,

I have a header and detail tables. I'm populating data in the detail table, but I want to create a check constraint on it based on a combination of values in the header and detail table.

Basically, header table has a bit column called Tag_Required, if the bit is checked then I need to make sure I supply Tag information in the detail table, if Tag_Required is not checked, then I don't need to pass anything into that column.

Can LLBL do this, I looked into setting this up right on SQL, but Check constraints are limited only to the specific table I'm working in, I can't link to a header table, so I think.

Thanks in advance.
  Top
goose
User



Location:
Central America
Joined on:
06-Aug-2007 18:21:05
Posted:
392 posts
# Posted on: 05-Feb-2008 20:22:29.  
please see: Using the generated code - Validation per field or per entity

gansodesoya  Top
tetris
User



Location:

Joined on:
05-Feb-2008 19:32:39
Posted:
3 posts
# Posted on: 05-Feb-2008 20:40:28.  
I can't seem to find that thread.. Do you have a link for it?
Thanks.
  Top
JimHugh
User



Location:
Davis, CA
Joined on:
16-Nov-2005 14:32:25
Posted:
191 posts
# Posted on: 05-Feb-2008 20:54:15.  
It's not a thread, it is a section in the documentation for LLBLGen that is installed along with the product.

Jim Hughes  Top
stefcl
User



Location:
Switzerland
Joined on:
23-Jun-2007 19:52:49
Posted:
210 posts
# Posted on: 06-Feb-2008 09:38:35.  
Validation can help but could be tricky to set up because it involves a related entity which might be out of sync... or not fetched at all (especially if you're using adapter).

I suggest you create two distinct validator classes (one that requires a value for Tag and an another one that doesn't) and decide at runtime which one you attach to the detail entity.

You could create a method in your header entity class which returns an instance of the appropriate validator...
Something like

Code:
public ValidatorBase GetDetailValidator()
{
     if(this.Tag_required)
         return new DetailValidatorWithTag();
     else
         return new DetailValidatorWithoutTag();
}


Or even easier, just one class which accepts a bool value in its constructor...
It seems to be an elegant way to solve the problem...
Anyway, I think I would use a database trigger to make sure it's impossible to insert records that violates the rule.
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.