This project is read-only.

Define generated properties

When NSQLObjects generates classes for a query or a fetch result, each column from a query will be mapped to a property. The actual property type is determined by one of the following rules in priority order.
  1. Column has an explicit definition in a query or a fetch body
  2. Column name has a default definition in the default section
  3. Column type has a default definition in the default section
  4. Implicit default column type
In addition to the property type, you can also select column modification rules and custom attributes that will be added to property definition.

Explicit column definition

query ProductPrices [[
	SELECT ProductID, ProductName, UnitPrice
	FROM Products
]] returns ProductPriceRow update "Products" {
	UnitPrice: decimal;
	readonly compare ProductID: int;

In this query we have explicit column definitions for the ProductID and UnitPrice columns. Syntax for explicit column definition is (See Syntax definition):
[“readonly” | “immutable” ] [ “compare” ] column “:” 
  type [ “[“ custom_attributes “]” ] ;

Readonly, immutable and compare are only valid for updatable queries and fetches.
Readonly informs that the column is never inserted or updated. This is typically used for identity columns.
Immutable columns are inserted but never updated. Typically used for primary key columns which are assigned only when an object is created.
Compare tells that the original value of column is used to identify a row that will be updated or deleted. This is typically used for primary key and timestamp columns. NSQLObjects will throw an exception if an update or delete operation tries to modify more than one row or no rows at all. NSQLObjects will make a copy of loaded record before it is modified. Original values will be used for update or delete comparisons.

After column type you can give C# custom attributes that will be included for property definition. For example:
ProductName: string [ Description("Name of product") ];

Custom attributes are emitted to generated code without any checks. You will detect possible errors when project is compiled.
If you need to emit [ or ] into custom attributes, enclose definition with double brackets [[ and ]].

Name based default

Last edited Nov 11, 2010 at 10:18 AM by nolics, version 5


No comments yet.