static DataDefine CreateMapping(Type type) { TypeInfo typeInfo = type.GetTypeInfo(); bool isNullable = false; if (typeInfo.IsGenericType) { Type frameType = type.GetGenericTypeDefinition(); if (frameType.FullName == "System.Nullable`1") { Type[] arguments = typeInfo.GetGenericArguments(); type = arguments[0]; typeInfo = type.GetTypeInfo(); isNullable = true; } } DataDefine define; if (type.IsArray) { if (type.FullName == "System.Byte[]") { define = new BytesDataDefine(type, true); } else { throw new LightDataException(string.Format(SR.DataDefineUnsupportFieldType, type)); } } else if (type.IsGenericParameter || typeInfo.IsGenericTypeDefinition) { throw new LightDataException(string.Format(SR.DataDefineUnsupportFieldType, type)); } else if (typeInfo.IsEnum) { define = new EnumDataDefine(type, isNullable); } else { TypeCode code = Type.GetTypeCode(type); switch (code) { case TypeCode.Empty: case TypeCode.Object: throw new LightDataException(string.Format(SR.DataDefineUnsupportFieldType, type)); case TypeCode.String: define = new PrimitiveDataDefine(type, true); break; default: define = new PrimitiveDataDefine(type, isNullable); break; } } return(define); }
/// <summary> /// 查询数据是否存在 /// </summary> /// <param name="mapping">数据映射表</param> /// <param name="query">查询表达式</param> /// <param name="level">安全级别</param> /// <returns>结果</returns> internal bool Exists(DataEntityMapping mapping, QueryExpression query, SafeLevel level) { bool exists = false; //Region region = new Region(0, 1); using (IDbCommand command = _dataBase.Factory.CreateExistsCommand(mapping, query)) { PrimitiveDataDefine pm = PrimitiveDataDefine.Create(typeof(Int32), 0); foreach (object obj in QueryDataReader(pm, command, null, level)) { exists = true; } } return(exists); }
private static DataDefine TransferDataDefine(DataFieldMapping fieldMapping) { DataDefine define = null; if (fieldMapping is PrimitiveFieldMapping) { if (fieldMapping.ObjectType == typeof(string)) { define = PrimitiveDataDefine.CreateString(fieldMapping.IsNullable, fieldMapping.Name); } else { if (fieldMapping.IsNullable) { Type itemstype = System.Type.GetType("System.Nullable`1"); Type type = itemstype.MakeGenericType(fieldMapping.ObjectType); define = PrimitiveDataDefine.Create(type, fieldMapping.Name); } else { define = PrimitiveDataDefine.Create(fieldMapping.ObjectType, fieldMapping.Name); } } } else if (fieldMapping is EnumFieldMapping) { EnumFieldMapping em = fieldMapping as EnumFieldMapping; if (fieldMapping.IsNullable) { Type itemstype = System.Type.GetType("System.Nullable`1"); Type type = itemstype.MakeGenericType(fieldMapping.ObjectType); define = EnumDataDefine.Create(type, em.EnumType, fieldMapping.Name); } else { define = EnumDataDefine.Create(fieldMapping.ObjectType, em.EnumType, fieldMapping.Name); } } else { throw new LightDataException(RE.OnlyPrimitiveFieldCanSelectSingle); } return(define); }
private static DataDefine TransferDataDefine(Type dataType, string name, bool isNullable) { DataDefine define = null; if (dataType == typeof(string)) { define = PrimitiveDataDefine.CreateString(isNullable, name); } else { if (isNullable) { Type itemstype = System.Type.GetType("System.Nullable`1"); Type type = itemstype.MakeGenericType(dataType); define = PrimitiveDataDefine.Create(type, name); } else { define = PrimitiveDataDefine.Create(dataType, name); } } return(define); }
private static DataDefine CreateMapping(Type type) { var typeInfo = type.GetTypeInfo(); var isNullable = false; if (typeInfo.IsGenericType) { var frameType = type.GetGenericTypeDefinition(); if (frameType.FullName == "System.Nullable`1") { var arguments = typeInfo.GetGenericArguments(); type = arguments[0]; typeInfo = type.GetTypeInfo(); isNullable = true; } } DataDefine define; if (type.IsArray) { if (type.FullName == "System.Byte[]") { define = new BytesDataDefine(true); } else { define = new ObjectDataDefine(type, true); } } // else if (type.IsGenericParameter || typeInfo.IsGenericTypeDefinition) { // throw new LightDataException(string.Format(SR.DataDefineUnsupportFieldType, type)); // } else if (type == typeof(Guid)) { define = new GuidDataDefine(isNullable); } else if (type == typeof(string)) { define = new StringDataDefine(true); } else if (type == typeof(DateTime)) { define = new DateTimeDataDefine(isNullable); } else if (type == typeof(decimal)) { define = new DecimalDataDefine(isNullable); } else if (typeInfo.IsEnum) { define = new EnumDataDefine(type, isNullable); } else if (type.IsPrimitive) { define = new PrimitiveDataDefine(type, isNullable); } else if (type == typeof(DBNull)) { throw new LightDataException(string.Format(SR.DataDefineUnsupportFieldType, type)); } else { define = new ObjectDataDefine(type, true); } return(define); }