Data Tier Generator – Planning

Now, here's my Entity definition. This definition would vary from project to project and would be the only thing I'd have to change.

[code:xml]
<nTier projectPrefix="prj">
  <entity name="Tag" primaryKeys="id">
      <properties>
          <property name="id" sqlType="bigint" notnull="true" />
          <property name="text" sqlType="nvarchar(50)" notnull="true" />
      </properties>
      <indices>
          <index columns="text" />
      </indices>
  </entity>
  <entity name="Article" primaryKeys="id">
      <properties>
          <property name="id" sqlType="bigint" notnull="true" />
          <property name="title" sqlType="nvarchar(255)" notnull="true" />
          <property name="content" sqlType="xml" />
      </properties>
      <indices>
          <index columns="title" />
      </indices>
  </entity>
  <entity name="ArticleTag" primaryKeys="articleId, tagId">
      <properties>
          <property name="articleId" sqlType="bigint" notnull="true" />
          <property name="tagId" sqlType="bigint" notnull="true" />
      </properties>
  </entity>
</nTier>
[/code]

Now, here's how it's all structured:

  • Each entity tag will correspond to a database table and most of the time an C# class. There're exceptions such as the link-tables. I'll explain that when I get to one.
  • The projectPrefix attribute specifies the prefix that would be added to each table and stored procedure generated. For example, the entity Article would generate a table prj_Article
  • Each property tag inside properties tag will correspond to a table column and a public property in the generated class.
  • The primaryKeys attribute can be used to provide a comma seperated list of primary key columns
  • The indices tag is used to specify nonclustered indexes for the table. The columns attribute accepts a comma seperated list of columns

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.