Gentle.NET Attribute
------------------------------------------------------------
Gentle.NET Attribute
------------------------------------------------------------
数据表特性(用在实体类上)
[TableName("Product", CacheStrategy.Temporary)]
注:缓存策略
public enum CacheStrategy
{
Never, // 每次都直接从数据库获取记录
Temporary, // 读取记录后丢到Cache中,并指定失效时间。每次查询时先尝试从cache中获取,若不存在才查询数据库
Permonent // 类似Tempory,但不指定失效时间
}
数据字段特性
针对不同的数据库以下特性部分有效,具体请查看pdf文档Page55-57
[Size]
[Type]
[IsNullable]
[IsUnique]
[IsPrimaryKey]
[IsForeignKey]
[IsAutoGenerated]
例如:主键,自增字段
[TableColumn("id", NotNull=true), PrimaryKey(AutoGenerated=true)]
protected int id;
[TableColumn("name", NullValue="")]
protected string name;
[TableColumn( "ph_Id", NotNull=true ), PrimaryKey( AutoGenerated=true ), SequenceName( "PROPERTYHOLDER_SEQ" )]
public virtual int Id
{
get { return id; }
set { id = value; }
}
Gentle.Framework Attribute
[Concurrency]
[CustomView]
[ForeignKey]
[Inheritance]
[PrimaryKey]
[SequenceName]
[SoftDelete]
[TableColumn]
[TableName]
数据视图特性(用在Property上)Gentle.Common.Attributes
以下特性可用在Property上
[Caption("Caption")]
[AllowSort(false)]
[ReadOnly(false)]
[Visible(false)]
例如
[Caption("Company"), ReadOnly(true)]
property string CompanyName
{
get{ return companyName; }
set{ companyName = value; }
}
[AllowSort(false)]
public string Name
{
get { return mName; }
set { mName = value; }
}
[Visible(false)]
public string Name
{
get { return mName; }
set { mName = value; }
}
数据校验特性
[RegexValidator(Expression=@"[A-Z]+[a-z])]
[RequiredValidator()]
[RangeValidator( Min=20.5, Max=100.5 )]
转载请注明出处:http://surfsky.cnblogs.com