Unique Constraint

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 13-Jul-2010 18:41:40   

LLBLGEN 3.0 .NET Frame work 2.0 LLBLGENRUNTIME framework adapter template

Hi,

Is there a way to construct unique constraint filter without defining the same in DB or designer ?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 13-Jul-2010 21:14:16   

Short Answer - No. How can you have a Unique Constraint filter if you do not have a Unique Constraint ? simple_smile

I'm assuming you have a set of columns which uniquly identify a row, but which are not defined in the database a primary key or unique constraint ? What you do in this case is fetch an entity collection using the values in these columns as a filter, and check that it only comes back with one row.

Matt

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Jul-2010 06:49:22   

....Howerver, you can use

adapter.FetchEntityUsingUniqueConstraint(IPredicateExpression....)

(from your previous threads I can see you are using Adapter). This will only returns the first occurrence from the resulset. This is the same as fetching a collection with parameter MaxItemsToReturn = 1, and then extract that entity from the collection.

LLBLGen generates methods that construct UCs, for example

customer, customer.ConstructFilterForUCCompanyName()

However, that generation is based on UCs defined on your DB. If you don't have such UCs LLBLGen wont generate such methods. Besides, you don't gain much doing this in code but no in DB as there is no indexes on such table fields.

David Elizondo | LLBLGen Support Team
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 14-Jul-2010 08:30:40   

daelmo wrote:

....Howerver, you can use

adapter.FetchEntityUsingUniqueConstraint(IPredicateExpression....)

(from your previous threads I can see you are using Adapter). This will only returns the first occurrence from the resulset. This is the same as fetching a collection with parameter MaxItemsToReturn = 1, and then extract that entity from the collection.

LLBLGen generates methods that construct UCs, for example

customer, customer.ConstructFilterForUCCompanyName()

However, that generation is based on UCs defined on your DB. If you don't have such UCs LLBLGen wont generate such methods. Besides, you don't gain much doing this in code but no in DB as there is no indexes on such table fields.

Got it. Thanks