comparison Source/Templates/ValidationAttributes.ttinclude @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 <#
2 {
3 var validationPrevBeforeGenerateModel = BeforeGenerateModel;
4
5 BeforeGenerateModel = tt =>
6 {
7 validationPrevBeforeGenerateModel(tt);
8
9 Usings.Add("BLToolkit.Validation");
10
11 foreach (var t in Tables.Values)
12 {
13 var maxLength = t.Columns.Values
14 .Where (x => x.Type == "string")
15 .Select(x => x.Length)
16 .OrderByDescending(x => x)
17 .FirstOrDefault()
18 // Get exponent slowly
19 .ToString().Length;
20
21 foreach (var c in t.Columns.Values)
22 {
23 if (c.Type == "string" && c.Length > 0)
24 c.Attributes.Add(string.Format("MaxLength({0," + maxLength + "})", c.Length));
25
26 if (!c.IsNullable)
27 c.Attributes.Add("Required");
28 }
29 }
30 };
31 }
32 #>