Unique constraints LLBLGEN 3.0

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 03-Jun-2010 15:17:27   

Hi,

In UI, I can see a tab named "Unique constraints " in field oriented elements.

I selected two columns (description, flag) and created Unique constraint in designer.

How can I use this in Code without having to again specify the unique columns ?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 03-Jun-2010 21:26:32   

In some target frameworks (e.g. LLBLGen Pro RTL) unique constraints are used to create extra constructors / filter presets. They're also used to define unique constraints in the Relational Model Data, for the fields mapped by the entity fields in the unique constraints.

Can you give us an example of what you want to achieve with your unique constraint...?

Matt

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 04-Jun-2010 06:09:46   

Hi,

Your example in documentation is like this

DataAccessAdapter adapter = new DataAccessAdapter(); CustomerEntity customer = new CustomerEntity(); customer.CompanyName = "Chop-suey Chinese"; adapter.FetchEntityUsingUniqueConstraint(customer, customer.ConstructFilterForUCCompanyName());

What I need?

In designer I have created unique constraint for CompanyName, Flag and named unique constraint as "CheckCustomer".

Before Inserting entity, I want to check whether this unique constraint combination exist and if yes do not insert.

Since I have created in designer unique constraint with name CheckCustomer", how can i write the code to achieve this instead of again defining unique constraints in code as per documention example above. This will reduce no of lines of code for me

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-Jun-2010 09:47:04   

customer.ConstructFilterForUCCompanyName()

The unique constraint must be passed explicitly to the fetch method. This is by design, since you can have more than one UC per entity.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 04-Jun-2010 10:54:59   

Thanks But I am trying to return true or false. What is the right way

private static bool isduplicaterecord() // check duplicate records in table { var adapteraccountnature = new DataAccessAdapter(); var accountnature = new AccountnatureEntity(); accountnature.Description = "test"; accountnature.Flag = ClubCentricBISpecific.StandardFlag.recordvalidflag; adapteraccountnature.FetchEntityUsingUniqueConstraint(accountnature, accountnature.ConstructFilterForUCDescriptionFlag()); if (**accountnature.Count **<= 0) { return false; // no matching records found } return true; // matching records found }

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-Jun-2010 11:01:21   

accountnature is an Entity not a collection, so there is no Count property.

You can check the (accountnature.IsNew == false) or you may check on (accountnature.Fields.State == EntityState.Fetched)

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 04-Jun-2010 11:16:41   

Walaa wrote:

accountnature is an Entity not a collection, so there is no Count property.

You can check the (accountnature.IsNew == false) or you may check on (accountnature.Fields.State == EntityState.Fetched)

Thanks