CommandBase - help on "Exists" and also where is best place to use

CommandBase - help on "Exists" and also where is best place to use

Old forum URL: forums.lhotka.net/forums/t/5388.aspx


SteveMc posted on Thursday, September 11, 2008

Just using CommandBase for first time - using it to run a stored procedure.
Based my work on "Exists" CommandBase in Project Tracker, but I'm a bit confused as to where the "Exists" command is actually used! Apart from its definition I can't find any other reference to it in the project - can you help please.

Basically I need to run my command after I've done a DataPortal_Insert, just need help on best way to do this. Thanks.

Added call to Dataportal_Insert - works ok. Just need to add extra business rules now.
Still can't follow "Exists" though!

triplea replied on Thursday, September 11, 2008

What exactly are you trying to achieve? Do you want to ensure that after an insert your object was actually saved in your data store?

In any case, you would normally use the Exists command before you load the data of an entry for which you have an ID. This could be done if you dont trust the data in the store you are retreiving from (e.g. you could be returning the data from a database you dont really have control over) but there are many other uses for it (or other commandbase objects).

JoeFallon1 replied on Thursday, September 11, 2008

One place you can use it is when you are on a screen and need to know if the user input ID exists in the DB or not so you can branch your code to Fetch the existing ID that is in the DB or else create a New Bo using DP_Create.

e.g.

If MyBO.Exists("someID") Then

  MyBO.FetchBO("someID")

Else

  MyBO.NewBO("someID")

End If

ayubu replied on Monday, September 15, 2008

Just to add

The commandbase was also designed to run query which involves a lot of records and just to return one record.

Let say Property of TotalAmount in Order object will need to fetch all invoice items to the client and summate them which not performance effective right just just write a commandbase object and let the database server do calculation and just get the total

Copyright (c) Marimer LLC