Adding custom code

Since the default templates create partial classes you can easily add custom code to generated Entities by creating a corresponding partial class in C#. You pass in your C# file as a code file parameter when calling esc. Such as:
esc /o bin\test.dll person.es person.cs

So if your entity is like this:
family test
{
	entity Person
	{
		field identity id int pid;
		field bytes data;
	}
}

You could define a corresponding class in C# and hook into your entity by overriding the Entity_Load method:
using System;

namespace test
{
	public partial class Person
	{
		protected override void Entity_Load()
		{
			//Custom code here.

			this.Persisting += new EventHandler<EventArgs<DbTransaction>>(Person_Persisting);
		}
		
		private void Person_Persisting(object sender, EventArgs<DbTransaction> e)
		{
			//Do some more custom code here.
		}
	}
}

With this method you can easily add anything you would like to your generated assembly.

Last edited Oct 16, 2006 at 11:30 PM by justinc, version 1

Comments

No comments yet.