Example #1
0
		static string MapType(Type type, ICustomAttributeProvider attributes, ref bool canBeNull) {
			switch (type.FullName) {
				case "System.Int32": return "int";
				case "System.Int64": return "bigint";
				case "System.Single": return "real";
				case "System.Double": return "float";
				case "System.Boolean": return "bit";
				case "System.String":
					var maxLength = attributes.SingleOrDefault<MaxLengthAttribute>();
					return string.Format("varchar({0})", maxLength == null ? "max" : maxLength.Length.ToString());
				case "System.DateTime": return "datetime";
				default:
					if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof (Nullable<>)) {
						canBeNull = true;
						return MapType(type.GenericTypeArguments[0], attributes, ref canBeNull);
					}
					throw new NotSupportedException("Don't know how to map " + type.FullName + " to a db type");
			}
		}