开发框架支持的两种ORM模型(静态类/实体类)
ORM简介
ORM是指对象关系映射,开发框架将ORM定义为静态类(Static Class)或实体类(Entity Class/Object Class),静态类是指只定义表结构的字段映射,这种类无任何方法或属性,只有对应字段名称定义。而实体类包含字段名称定义和对应的属性,下面是两种不同的ORM类定义:
[付款类型]的静态类ORM,
///<summary>
/// ORM模型, 数据表:tb_PayType,由ClassGenerator自动生成
/// </summary>
[ORM_ObjectClassAttribute("tb_PayType", "PayType", true)]
public sealed class tb_PayType
{
public static string __TableName ="tb_PayType";
public static string __KeyName = "PayType";
[ORM_FieldAttribute(SqlDbType.Int,4,false,false,false,false,false)]
public static string isid = "isid";
[ORM_FieldAttribute(SqlDbType.VarChar,10,false,true,true,false,false)]
public static string PayType = "PayType";
[ORM_FieldAttribute(SqlDbType.NVarChar,40,false,true,false,false,false)]
public static string TypeName = "TypeName";
}
如ORM定义为静态类,DAL层指定的SQL命令生成器必须是GenerateSqlCmdByTableFields.
[销售人员]的实体类ORM:
///<summary>
/// ORM模型, 数据表:tb_Person,由ClassGenerator自动生成
/// </summary>
[ORM_ObjectClassAttribute("tb_Person", "ISID", true)]
public sealed class tb_Person
{
#region 所有字段的局部变量定义
#endregion
public static string __TableName = "tb_Person";
public static string __KeyName = "ISID";
#region 所有字段名常量
public const string _ISID = "ISID";
public const string _SalesCode = "SalesCode";
public const string _SalesName = "SalesName";
public const string _Department = "Department";
public const string _InUse = "InUse";
#endregion
#region 所有字段属性
[ORM_FieldAttribute(SqlDbType.Int, 4, false, false, true, false, false)]
public int ISID { get { return F_ISID; } set { F_ISID = value; } }
[ORM_FieldAttribute(SqlDbType.VarChar, 20, false, true, false, false, false)]
public string SalesCode { get { return F_SalesCode; } set { F_SalesCode = value; } }
[ORM_FieldAttribute(SqlDbType.NVarChar, 40, false, true, false, false, false)]
public string SalesName { get { return F_SalesName; } set { F_SalesName = value; } }
[ORM_FieldAttribute(SqlDbType.Char, 1, false, true, false, false, false)]
public string InUse { get { return F_InUse; } set { F_InUse = value; } }
#endregion
}
如ORM定义为实体类,DAL层指定的SQL命令生成器必须是GenerateSqlCmdByObjectClass.
参考:dalPerson.cs
扫一扫加微信