How to validate fields when using UpdateEntitiesDirectly

Posts   
 
    
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 10-Apr-2006 12:40:56   

Hi,

Obviously in this case the built in validator class doesn't work. Which is the recommended method of field validation?

In my situation I don't want the amount to be less then 0. So I have to compare the value of the amount field, to the parameter value quantity.

Is it possible to do that, without fetching the object?

Thanks

Gabor

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-Apr-2006 14:50:19   

I'm not sure what excatly are you trying to do, maybe if you post the UPDATE sql query that you want to execute it would be more obvious to me.

If you are setting a field ("amount") and you don't want it to be set to Zero. I beleive this check can be made in you logic code before calling the UpdateEntitiesDirectl(), I mean don't accept a value of Zero to be set to your entity's field.

Or you may use the Validate method in your entity's validator class to check for the field value. This method is called when a field value changes.

You may also use Validation per entity as discussed in the LLBLGen Pro documentation manual, and you may explicitly call the Entity.Validate() method before calling the UpdateEntitiesDirectly()

Please refer to "Using the generated code -> Validation per field or per entity" section in the LLBLGen Pro documentation manual.

Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 10-Apr-2006 15:27:20   

Thanks for the quick reply,

In my case, I have a productStore entity.

When I sale a product, the saled amount have to be fewer than the stored amount in the productStore, ie. the ProductStore.Amount has to be greater than 0.

For the perfomance reason I don't want to fetch the product entity, but set the amount via UpdateEntitiesDirectly, but how can I control the amount in the productStore via field expression?

Dim store As New ProductSoreEntity()

store.Fields(CInt(storeFieldIndex.Amount)).ExpressionToApply = storeFields.Amount - saledAmount

Is it any mode, to compare the ProductStore.amount to the saledAmount, and execute the update query only, when the SaledAmount<ProductStore.Amount?

Thanks

Gabor

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Apr-2006 08:29:56   

Sorry, but I'm still confused

Please post the UPDATE sql query that you want to execute it would be more obvious to me.

Thanks

Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 11-Apr-2006 08:53:53   

Problem solved.

I has to add a check constrain to the productStore table amount field, to be greater than 0.

Apologise for the silly question

Gabor disappointed