Assembly: Microsoft.SqlServer.Smo (in microsoft.sqlserver.smo.dll)
An event class represents one type of event used by your Notification Services application. When you define your application, you define an event class for every type of event that you maintain in the application database.
If you remove an event class from an application, updating the application deletes the underlying tables and indexes in the application database. Any data existing in the original event class tables is permanently deleted.
You can have 0 to 64 event classes in a single Notification Services application. If you maintain events in external databases and query those databases in your subscription rules, you do not define event classes for these events.
The following examples show event class definitions using all event class properties and using all methods for adding fields to the event class:
EventClass flightEvents = new EventClass(myApplication, "FlightEvents"); flightEvents.FileGroup = "PRIMARY"; // Add an orgin field to the end of the field collection EventField eventOrgin = new EventField(flightEvents, "LeavingFrom"); eventOrgin.Type = "nvarchar(6)"; eventOrgin.TypeModifier = "not null"; flightEvents.EventFields.Add(eventOrgin); // Define a price field and add it at position 1 EventField eventPrice = new EventField(flightEvents, "Price"); eventPrice.Type = "float"; flightEvents.EventFields.Add(eventPrice, 1); // Define a destination field and add it before the Price field EventField eventDestination = new EventField(flightEvents, "GoingTo"); eventDestination.Type = "nvarchar(6)"; flightEvents.EventFields.Add(eventDestination, "Price"); // Add the event class to the application myApplication.EventClasses.Add(flightEvents); // Add an index to the event class to help improve performance flightEvents.IndexSqlStatements.Add( "CREATE INDEX FlightEventsIndex ON MyAppSchema.FlightEvents " + "( LeavingFrom, GoingTo );"); // Define a chronicle for the class EventChronicle ec1 = new EventChronicle(flightEvents, "FlightEventChonicle"); ec1.SqlStatements.Add( "CREATE TABLE MyAppSchema.FlightEventChronicle " + " (LeavingFrom nvarchar(6), GoingTo nvarchar(6), " + " Price float);"); ec1.SqlStatements.Add( "CREATE INDEX FlightEventChronicleIndex " + "ON MyAppSchema.FlightEventChronicle " + "( LeavingFrom, GoingTo );"); flightEvents.EventChronicles.Add(ec1); // Define the event chronicle rule EventChronicleRule ec1Rule = new EventChronicleRule(flightEvents, "FlightEventChronicleRule"); ec1Rule.Action = "INSERT MyAppSchema.FlightEventChronicle " + " (LeavingFrom, GoingTo, Price) " + " SELECT LeavingFrom, GoingTo, Price " + " FROM MyAppSchema.FlightEvents;"; ec1Rule.ActionTimeout = new TimeSpan(0, 1, 20); flightEvents.EventChronicleRule = ec1Rule;