Arguments in CFQL


CFQL methods can take arguments. Arguments in CFQL are composed of an optional type name and a name.

If the type name isn’t specified CodeFluent Entities looks for a property in the current entity matching the argument name.

For instance, instead of writing:

<Product>
  <Id />
  <Code />
  <Price />
 
  <cf:method name="LoadByCode" body="load(string code) where Code = @code" />
</Product>

You can write:

<cf:method name="LoadByCode" body="load(Code) where Code = @Code" />

Note: CFQL is case insensitive, writing “Code” or “code” or “LOAD” or “load” doesn’t matter.

This actually allows you to write flexible models: since if you change the property type, you won’t have to update your methods.

Keeping the same concern in mind, you can write expressions using entity names instead of their keys, such as:

<cf:method name=”LoadByRole” body=”load(Role Role) where Role = @Role” />

This should be preferred to writing methods such as this one:

<cf:method name=”LoadByRole” body=”load(guid roleId) where Role.Id = @roleId” />

The result will indeed be the same, however, if you change the type of the Role identifier, or if you update the Role entity to have a composite key your code will break. To the contrary, using the first method using the “Role = @Role” statement will keep on working.

  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