标签:
在对数据更新时,会按属性设定长度进行检查,如果超过,会抛出异常,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;
}
}
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