Home > Developing Using CodeFluent Entities > Use Entities Rather Than Their Keys in CFQL

Use Entities Rather Than Their Keys in CFQL


CFQL is made to use entities directly, you don’t have to use their keys explicitly (even though you can). The key point in CFQL is to be decoupled from the database’s physical definition, so keep it as simple as possible using entities for maximum flexibility. Here’s an example illustrating this point. One could be tempted to write such a CFQL query:

<cf:method name="DeleteByRoleId" body="delete(int RoleId) where Role.Id=@RoleId " />

Of course, this method is valid, however writing so implies that the identifier of the Role entity is of the integer type, so if you change its type, or change its key into a composite key, you’ll have to write this method over. However, using entities directly instead of their keys solves this issue:

<cf:method name="DeleteByRole" body="delete(Role) where Role=@Role" />

Both CFQL queries will actually produce the same SQL statement, however the second version is way more flexible.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s