Thursday, September 30, 2010

CF: ORM EntityDelete without EntityLoad

I must admit I am not a fan of the EntityDelete() function. Its inability to handle multiple records always nagged me. I know I can allways go back to CFQUERY or use ormexecutequery(). But what nagged me the most appeared to be the need to do an EntityLoad before I could remove the entity/record. This could potentially introduce unneeded database reads and latency.
e.g.:
myBook = EntityLoad("Book", 100, true);
EntityDelete(myBook);


Well it turnes out that the use of EntityLoad is not required. A colleague suggested I try the following instead which would eliminate the load operation, and since I thought that was pretty neat I am sharing ;o)

mybook = new Book();
mybook.setBOOKID(100);
EntityDelete(mybook);

In this fashion, you are creating the object reference in memory and guaranteeing that there is only one DB interaction at DELETE.

Cheers,
Bilal

2 comments:

Troy said...

Hi,

I just wanted to say that I really enjoyed your blog and this post. You make some very informative points. Keep up the great work!

-
Delphi development

bman said...

Thanks for the feeback