| 0 | 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 #> |