Gentle.NET Attribute

本文详细介绍了Gentle.NET框架中用于实体类及属性的数据表特性、字段特性和视图特性,包括缓存策略、字段大小、类型定义、主键设置等,并提供了具体的使用示例。

------------------------------------------------------------
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 )]
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值