比如
[Table(Name="dbo.User")]
public partial class User : INotifyPropertyChanging, INotifyPropertyChanged
{
...
   [Column(Storage="_Id", AutoSync=AutoSync.OnInsert, DbType="BigInt NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
   public long Id
   {
       ...
   }
...
}
请教:我如何才能获取到 User.Id 的DbType的值
谢谢

解决方案 »

  1.   

    补充一点,我使用的linq to sql 自动生成的 dbml 文件
    先行谢过
      

  2.   

    已经通过反射取得,不知还有其他方法没var ss = typeof(User).GetProperty("Id");
            object[] attributes = ss.GetCustomAttributes(true);
            for (int i = 0, j = attributes.Length; i < j; i++)
            {
                if (attributes[i] is ColumnAttribute)
                {
                    ColumnAttribute ca = attributes[i] as ColumnAttribute;
                    Response.Write(ca.DbType);
                }            
            }
      

  3.   


    var attrInfo = typeof(User).GetProperty("Id").GetCustomAttributes(typeof(ColumnAttribute), true)[0] as ColumnAttribute;
    Response.Write(attrInfo.DbType);
    只要确认 Id 属性(字段)存在就可以直接使用。
    还没人回答,哪怕顶一次也好,让我咋个结贴哦
      

  4.   

    要从linq to sql的自动映射文件中获取,只能使用反射获取属性值。
    否则你需要自己写SQL语句到数据库直接获取。