Gentle中的数据表实体类相关自定义属性的设置和获得

1.自定义 表名属性 TableNameAttribute
2.自定义 主键属性 PrimaryKeyAttribute
3.自定义 列名属性 TableColumnAttribute
4.数据表person对应的实体类person.cs
5.获得person.cs类型实体 对应的表名及字段名

=========================================
下面的属性代码文件 都直接建立在App_Code下 以方便使用

1.自定义 表名属性 TableNameAttribute
------------------------------------

ContractedBlock.gif ExpandedBlockStart.gif
None.gifusing System;
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**//// <summary>
InBlock.gif
/// TableNameAttribute 的摘要说明
ExpandedBlockEnd.gif
/// </summary>

None.gif
None.gif[AttributeUsage( AttributeTargets.Class, AllowMultiple
=false, Inherited=true )]
None.gif
public sealed class TableNameAttribute : Attribute
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
private string name;
InBlock.gif    
private string schema;
InBlock.gif    
//private CacheStrategy cacheStrategy = GentleSettings.DefaultCacheStrategy;
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// The constructor for the TableName attribute.
InBlock.gif    
/// </summary>
ExpandedSubBlockEnd.gif    
/// <param name="name">The name of the database table used to store instances of this class.</param>

InBlock.gif    public TableNameAttribute( string name )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
this.name = name;
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// The constructor for the TableName attribute.
InBlock.gif    
/// </summary>
InBlock.gif    
/// <param name="name">The name of the database table used to store instances of this class.</param>
InBlock.gif    
/// <param name="strategy">The cache stratgey to use for instances of this type. <see 
ExpandedSubBlockEnd.gif
    /// cref="CacheStrategy"/> for a list of available options.</param>

InBlock.gif    //public TableNameAttribute( string name, CacheStrategy strategy )
InBlock.gif    
//{
InBlock.gif    
//    this.name = name;
InBlock.gif    
//    this.cacheStrategy = strategy;
InBlock.gif    
//}
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// The name of the database table used to store instances of this class.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public string Name
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn name; }
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// The optional schema name with which to prefix the table name in queries.
InBlock.gif    
/// This value overrides the default schema definition (if present) in the
InBlock.gif    
/// configuration file. Note: this property is currently unused. 
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public string Schema
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn schema; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ schema = value; }
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**////// <summary>
InBlock.gif    
///// The cache behavior for objects of this type. <see cref="CacheStrategy"/> 
InBlock.gif    
///// for a list of available options.
ExpandedSubBlockEnd.gif    
///// </summary>

InBlock.gif    //public CacheStrategy CacheStrategy
InBlock.gif    
//{
InBlock.gif    
//    get { return cacheStrategy; }
InBlock.gif    
//    set { cacheStrategy = value; }
InBlock.gif    
//}
ExpandedBlockEnd.gif
}

None.gif

2.自定义 主键属性 PrimaryKeyAttribute
------------------------------------
ContractedBlock.gif ExpandedBlockStart.gif
None.gifusing System;
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**//// <summary>
InBlock.gif
/// PrimaryKeyAttribute 的摘要说明
ExpandedBlockEnd.gif
/// </summary>

None.gif[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true, Inherited = true)]
None.gif
public sealed class PrimaryKeyAttribute : Attribute
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
private bool autoGenerated = false;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Set this property to true for primary keys that are automatically assigned
InBlock.gif    
/// by the database on insert (identity columns in SQL server terminology). 
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public bool AutoGenerated
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn autoGenerated; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ autoGenerated = value; }
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

3.自定义 列名属性 TableColumnAttribute
--------------------------------------
ContractedBlock.gif ExpandedBlockStart.gif
None.gifusing System;
None.gif
using System.Data;
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**//// <summary>
InBlock.gif
/// TableColumnAttribute 的摘要说明
ExpandedBlockEnd.gif
/// </summary>

None.gif[AttributeUsage( AttributeTargets.Property | AttributeTargets.Field, AllowMultiple=false, Inherited=true )]
None.gif
public class TableColumnAttribute : Attribute
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
private string name;
InBlock.gif    
private bool notNull;
InBlock.gif    
private int size;
InBlock.gif    
private bool hasDbType = false// true when DbType property has been set
InBlock.gif
    private long dbType;
InBlock.gif    
private object nullValue = null;
InBlock.gif    
private bool handleEnumAsString = false;
InBlock.gif    
private bool isReadOnly = false;
InBlock.gif    
private bool isUpdateAfterWrite = false;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Constructor for table columns that are named after their property counterpart
InBlock.gif    
/// and whose value cannot be null.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public TableColumnAttribute()
InBlock.gif        : 
this(nulltrue)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Constructor for table columns that are named after their property counterpart.
InBlock.gif    
/// </summary>
ExpandedSubBlockEnd.gif    
/// <param name="notNull">A boolean telling whether null values are allowed in the database</param>

InBlock.gif    public TableColumnAttribute(bool notNull)
InBlock.gif        : 
this(null, notNull)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Constructor for table columns whose value cannot be null.
InBlock.gif    
/// </summary>
ExpandedSubBlockEnd.gif    
/// <param name="name">The name of the database column</param>

InBlock.gif    public TableColumnAttribute(string name)
InBlock.gif        : 
this(name, true)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Constructor for table columns.
InBlock.gif    
/// </summary>
InBlock.gif    
/// <param name="name">The name of the database column</param>
ExpandedSubBlockEnd.gif    
/// <param name="notNull">A boolean telling whether null values are allowed in the database</param>

InBlock.gif    public TableColumnAttribute(string name, bool notNull)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
this.name = name;
InBlock.gif        
this.notNull = notNull;
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// The name of the database column for storing the property decorated with this attribute.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public string Name
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn name; }
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// This property (defaults to true) can be used to specify whether NULL values are
InBlock.gif    
/// allowed in the database. This allows the framework to fail early if a constraint
InBlock.gif    
/// is violated.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public bool NotNull
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn notNull; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ notNull = value; }
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// The database type of the field in the database. Beware that the DbType enumeration
InBlock.gif    
/// values are NOT the ones used by the individual providers. Gentle does NOT convert
InBlock.gif    
/// the DbType to a "best match" for the provider. It is therefore recommended that 
InBlock.gif    
/// you use the DatabaseType below until a better type definition system is available.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    [Obsolete("Please use DatabaseType instead.")]
InBlock.gif    
public DbType DbType
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn (DbType)dbType; }
InBlock.gif        
set
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            hasDbType 
= true;
InBlock.gif            dbType 
= (long)value;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// The database type of the field in the database. Convert the actual database type
InBlock.gif    
/// enumeration to a long by casting it in the declaration.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public long DatabaseType
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn dbType; }
InBlock.gif        
set
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            hasDbType 
= true;
InBlock.gif            dbType 
= value;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// The size or length of the field in the database. String properties will be clipped
InBlock.gif    
/// to fit.
InBlock.gif    
/// This feature will obsoleted once Gentle is capable of extracting type and size 
InBlock.gif    
/// information directly from the database. If specified, the values must match
InBlock.gif    
/// those extracted from the database (when implemented).
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public int Size
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn size; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ size = value; }
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// This property indicates whether a DbType was specified. This construct is necessary
InBlock.gif    
/// because the DbType enum has no value for undefined.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public bool HasDbType
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn hasDbType; }
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Obsolete, use NullValue instead.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    [Obsolete("Use NullValue instead.")]
InBlock.gif    
public object MagicValue
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn nullValue; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ nullValue = value; }
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// This value of this property is used when a column is NotNull and the property value
InBlock.gif    
/// is null.  If this is undefined the framework will throw an error for NotNull columns
InBlock.gif    
/// whose values are null.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public object NullValue
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn nullValue; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ nullValue = value; }
ExpandedSubBlockEnd.gif    }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif    
NullValue Helper Properties for VB.NET Users#region NullValue Helper Properties for VB.NET Users
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// This property allows type-safe setting of the NullValue for VB users.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public int NullValue_int
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ NullValue = value; }
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// This property allows type-safe setting of the NullValue for VB users.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public NullOption NullValue_opt
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ NullValue = value; }
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif    
#endregion

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// This value indicates that the column should not be set on insert and update. It is
InBlock.gif    
/// primarily useful for columns that are set internally by the database.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public bool IsReadOnly
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn isReadOnly; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ isReadOnly = value; }
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// This value indicates that the column must be read after each insert and update. It is
InBlock.gif    
/// primarily useful for columns that are set internally by the database. Note that using
InBlock.gif    
/// this feature (by setting this to true for any column) will significantly impact 
InBlock.gif    
/// performance for the worse, as for every update/insert another select will be 
InBlock.gif    
/// performed. Also, fields will be updated using reflection after select, which is also
InBlock.gif    
/// quite slow (depending on the number of columns).
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public bool IsUpdateAfterWrite
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn isUpdateAfterWrite; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ isUpdateAfterWrite = value; }
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// If member which has this attribute attached is enum then this property
InBlock.gif    
/// indicates wheter framework saves it as string or as integer.
InBlock.gif    
/// Default is false, ie enums are saved as integers
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public bool HandleEnumAsString
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn handleEnumAsString; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ handleEnumAsString = value; }
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
None.gif
public enum NullOption
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// &lt;type&gt;.MinValue will be stored as NULL, and NULL will be read as &lt;type&gt;.MinValue.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    MinValue,
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// &lt;type&gt;.MaxValue will be stored as NULL, and NULL will be read as &lt;type&gt;.MaxValue.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    MaxValue,
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 0 (or the equivalent for other numeric types) will be stored as NULL, and NULL will be read as 0.
ExpandedSubBlockEnd.gif    
/// </summary> This value can only be used with numeric types (such as decimal).

InBlock.gif    Zero,
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Guid.Empty will be stored as NULL, and NULL will be read as Guid.Empty. This value can only be
InBlock.gif    
/// used with Guid fields.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    EmptyGuid
ExpandedBlockEnd.gif}

4.数据表person对应的实体类person.cs
------------------------------------
ContractedBlock.gif ExpandedBlockStart.gif
None.gifusing System;
None.gif
using System.Data;
None.gif
using System.Configuration;
None.gif
using System.Web;
None.gif
using System.Web.Security;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.WebControls.WebParts;
None.gif
using System.Web.UI.HtmlControls;
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**//// <summary>
InBlock.gif
/// person 的摘要说明
ExpandedBlockEnd.gif
/// </summary>

None.gif
None.gif[TableName(
"person")]
None.gif
public class person
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
public person()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
//[TableColumn("personID", NotNull = true), PrimaryKey]
InBlock.gif
    protected int _personID;
InBlock.gif    
//[TableColumn("personName", NotNull = true)]
InBlock.gif
    protected string _personName = String.Empty;
InBlock.gif
InBlock.gif    [TableColumn(
"personID", NotNull = true), PrimaryKey]
InBlock.gif    
public int PersonID
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn _personID; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ _personID = value; }
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    [TableColumn(
"personName", NotNull = true)]
InBlock.gif    
public string PersonName
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn _personName; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ _personName = value; }
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

5.获得person.cs类型实体 对应的表名及字段名
------------------------------------------
ContractedBlock.gif ExpandedBlockStart.gif
None.gifprotected void Button1_Click(object sender, EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    person aPerson 
= new person();
InBlock.gif    aPerson.PersonID 
= 22;
InBlock.gif    aPerson.PersonName 
= "zhangsan";
InBlock.gif
InBlock.gif    Type aType 
= aPerson.GetType();
InBlock.gif
InBlock.gif    
//类实体公开属性对应的列名属性
InBlock.gif
    PropertyInfo[] aPropertyInfos = aType.GetProperties();
InBlock.gif    
string strPublicProperty = " ";
InBlock.gif    
for (int i = 0; i < aPropertyInfos.Length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        PropertyInfo aPropertyInfo 
= (PropertyInfo)aPropertyInfos[i];
InBlock.gif        strPublicProperty 
+= i.ToString() + " : 实体属性名 " + aPropertyInfo.Name;
InBlock.gif        strPublicProperty 
+= " 对应值 " + aPropertyInfo.GetValue(aPerson, null).ToString() + " ";
InBlock.gif        
object[] attrs = aPropertyInfo.GetCustomAttributes(typeof(TableColumnAttribute), true);
InBlock.gif        
for (int m = 0; m < attrs.Length; m++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            strPublicProperty 
+= " 对应列名 " + ((TableColumnAttribute)attrs[m]).Name;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
this.TextBox1.Text = strPublicProperty;
InBlock.gif
InBlock.gif
InBlock.gif    
//FieldInfo[] aFieldInfos = aType.GetFields();
InBlock.gif    
//string strPublicField = " ";
InBlock.gif    
//for (int j = 0; j < aFieldInfos.Length; j++)
InBlock.gif    
//{
InBlock.gif    
//    FieldInfo aFieldInfo = (FieldInfo)aFieldInfos[j];
InBlock.gif    
//    strPublicField += j.ToString() + " : " + aFieldInfo.Name + " ";
InBlock.gif    
//}
InBlock.gif    
//this.TextBox2.Text = strPublicField;
InBlock.gif    
InBlock.gif
InBlock.gif    
//类实体对应的表名属性
InBlock.gif
    string strTablePKName = " ";
InBlock.gif    
object[] attrsAA = aType.GetCustomAttributes(typeof(TableNameAttribute), true);
InBlock.gif    
for (int n = 0; n < attrsAA.Length; n++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        strTablePKName 
+= " " + ((TableNameAttribute)attrsAA[n]).Name;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
//类实体对应的主键属性
InBlock.gif
    MemberInfo[] aMemberInfos = aType.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
InBlock.gif    
string strMemberInfo = " ";
InBlock.gif    
for (int k = 0; k < aMemberInfos.Length; k++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        MemberInfo aM 
= aMemberInfos[k];
InBlock.gif        
object[] attrs = aM.GetCustomAttributes(typeof(PrimaryKeyAttribute), true);
InBlock.gif        
for (int m = 0; m < attrs.Length; m++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            strTablePKName 
+= " 主键 " + aM.Name;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
this.TextBox2.Text = strTablePKName;
InBlock.gif   
ExpandedBlockEnd.gif}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值