2012-09-25 44 views
0

在我的sql數據庫中,我有一個數字(3,2)字段,我想要綁定到一個文本框。當Linq to SQL引入該字段時,它會將該字段轉換爲它的linq對象上的一個小數。是否可以訪問數字精度和縮放比例,以便在自定義控件的情況下使用它們進行驗證或綁定?最終我想阻止用戶在UI端輸入兩個以上的小數點。通過linq訪問SQL數據類型屬性

+0

http://geekswithblogs.net/AzamSharp/archive/2008/03/30/120875.aspx –

回答

0

我發現你可以做這樣的事情

 string val = String.Empty; 

     Type t = obj.GetType(); 
     PropertyInfo prop = t.GetProperty(fieldName); 
     object[] info = prop.GetCustomAttributes(typeof(ColumnAttribute), true); 

     if (info.Length == 1) 
     { 
      ColumnAttribute ca = (ColumnAttribute)info[0]; 
      string attr = ca.DbType 
          //... parse attr to get the info you want 
     } 

     return val; 

,因爲你必須解析出字符串得到什麼我正在尋找這是不理想的。但它的工作。