码迷,mamicode.com
首页 > 其他好文 > 详细

对象结构

时间:2015-02-11 16:26:24      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

以下演示了对象写法

 在对数据更新时,会按属性设定长度进行检查,如果超过,会抛出异常,string默认长度为30
    [CRL.Attribute.Table(TableName="table1")]//映射表名为table1
    public class ModelTest:CRL.IModelBase
    {

        [CRL.Attribute.Field(FieldIndexType = CRL.Attribute.FieldIndexType.非聚集唯一)]//非聚集唯一索引
        public string No
        {
            get;
            set;
        }
        [CRL.Attribute.Field(FieldIndexType = CRL.Attribute.FieldIndexType.非聚集)]//非聚集索引
        public string DataType
        {
            get;
            set;
        }
        [CRL.Attribute.Field(Length=100)]//长度为100
        public string BarCode
        {
            get;
            set;
        }
        /// 自动关联查询
        /// 值等同为 select Name as ProductName from ProductData where BarCode=ModelTest.ModelTest
        [CRL.Attribute.Field(ConstraintType = typeof(ProductData), ConstraintField = "$BarCode=BarCode", ConstraintResultField = "Name")]
        public string ProductName
        {
            get;
            set;
        }
        [CRL.Attribute.Field(ColumnType = "decimal(18,4)")]//强制指定字段类型,如果不指定则默认为decimal(18,2)
        public decimal Price
        {

            get;
            set;
        }
    }

MSSQL数据库,对象和字段类型对应关系如下

    Dictionary<type, string=""> dic = new Dictionary<type, string="">();
    //字段类型对应
    dic.Add(typeof(System.String), "nvarchar({0})");
    dic.Add(typeof(System.Decimal), "decimal(18, 2)");
    dic.Add(typeof(System.Double), "float");
    dic.Add(typeof(System.Single), "real");
    dic.Add(typeof(System.Boolean), "bit");
    dic.Add(typeof(System.Int32), "int");
    dic.Add(typeof(System.Int16), "SMALLINT");
    dic.Add(typeof(System.Enum), "int");
    dic.Add(typeof(System.Byte), "SMALLINT");
    dic.Add(typeof(System.DateTime), "datetime");
    dic.Add(typeof(System.UInt16), "SMALLINT");
    dic.Add(typeof(System.Int64), "bigint");
    dic.Add(typeof(System.Object), "nvarchar(30)");
    dic.Add(typeof(System.Byte[]), "varbinary({0})");
    dic.Add(typeof(System.Guid), "nvarchar(50)");

对象结构

标签:

原文地址:http://www.cnblogs.com/hubro/p/4286347.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!