Home > .NET Domain Model, Developing Using CodeFluent Entities > Adding Attributes On CodeFluent Entities Generated Properties

Adding Attributes On CodeFluent Entities Generated Properties

CodeFluent Entities provides an attribute concept which can be defined on any other CodeFluent Entities concept. You can actually easily see this when navigating the documentation in the CodeFluent Schema Reference (in the Reference Guide):


As you can see all concepts (project, entity, property, method, rule, etc.) all support a sub-concept named attribute and it just so happens that this platform independent concept of an attribute is translated into an actual .NET attribute by the Business Object Model Producer. (NOTE: in fact, this is the default behavior, as an attribute can actually be anything you need. The attribute has a “class” property, and by default, this class is empty. Attributes with an empty class are translated by the BOM producer as .NET custom attributes)

Say for instance that you developed a handmade attribute named Sample in your project with a Description property which you’d like to set on one of your properties for instance.

Select your property and use the “Add Attribute” button in the ribbon:


A new dialog pops-up and lets you specify your attribute:


Note: using the “…” button you can use an already existing .NET attribute.

Then your attribute will appear on the surface under its related concept.


If you select your attribute, you’ll then be able to define its arguments from the Property Grid:


Clicking on the “…” button will open the following dialog in which you’ll be able to add your argument properties such as our Description property:


Then if you generate your model again with the BOM producer on, the generated Name property of the Customer class will look as follows:

[Sample(Description=”This is a description!”)]
public string Name
return this._name;

By the way, you can do all this in XML in your model as well:

<cf:entity name=”Customer”>
<cf:property name=”Id” />
<cf:property name=”Name”>
<cf:attribute name=”Sample”>
<cf:argument name=”Description” expression=”This is a description!” />

  1. Peter Stanford
    February 6, 2013 at 4:16 am

    I’d like to be able to add an attribute that becomes the description of a column in a SQL Server table, not just in my generated class. For example, if I manually design a table in SQL Server Management Console, there is a property/attribute for each column called “Description” which allows me to describe what that particular column means. This is useful for database documentation and also for articulating to clients what each property in my entity is for.

    Is there a way to do this or does the above article explain it and I’ve missed something?

  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