This project is read-only.

Common business logic

In many project you have common field and behaviors across several or all database tables. In NSQLObjects we can define “entities”. Query results (rows) and fetches can inherit from entities. Entities will generate partial class that can be extended through normal partial class extensions. For example, in the Northwind database, several tables have similar address columns.

We can define base entity AddressEntity and use it in queries. For example
entity AddressEntity {
  Address: string;
  City: string;
  Region: string;
  PostalCode: string;			
  Country: string;

query CustomerAddresses [[
  SELECT CustomerID, CompanyName, Address, City, Region, PostalCode, 
    Country, Phone, Fax
  FROM Customers
]] returns CustomerAddressRow inherits AddressEntity;

query SupplierAddresses [[
  SELECT SupplierID, CompanyName, Address, City, Region, PostalCode,
    Country, Phone, Fax
  FROM Suppliers
]] inherits AddressEntity;

Now all properties defined in the AddressEntity will form a common base class. The additional columns in CustomerAddresses: CustomerID and CompanyName will go to the query specific class CustomerAddressRow. Now we can implement custom login to either the AddressEntity class or the CustomAddressRow class. All login implemented in AddressEntity will be shared between all queries and fetches using this class as base class.

For samples on how to customize how updatable rows are validated and updated to database, please see:

SubmitChanges events

Last edited Oct 26, 2010 at 9:57 AM by nolics, version 2


No comments yet.