private static TypeUsage GetStoreTypeUsage(DbModel model, SimpleTypeDescriptor simpleTypeDescriptor) { TypeUsage typeUsage = null; if (!string.IsNullOrEmpty(simpleTypeDescriptor.StoreTypeName)) { PrimitiveType primitiveType = model.ProviderManifest.GetStoreTypes().SingleOrDefault(t => string.Compare(t.Name, simpleTypeDescriptor.StoreTypeName, true) == 0); if (primitiveType == null) { throw new InvalidOperationException(string.Format("Store edm type with name '{0}' is not found.", simpleTypeDescriptor.StoreTypeName)); } typeUsage = GetTypeUsage(primitiveType.GetEdmPrimitiveType(), simpleTypeDescriptor); if (typeUsage == null) { throw new InvalidOperationException(string.Format("Type usage for type with name '{0}' is not found.", simpleTypeDescriptor.StoreTypeName)); } } else { SimpleType simpleType = GetSimpleEdmType(model, simpleTypeDescriptor.Type); if (simpleType == null) { throw new InvalidOperationException(string.Format("Edm type is not found for type '{0}'.", simpleTypeDescriptor.Type.FullName)); } typeUsage = GetTypeUsage(simpleType, simpleTypeDescriptor); if (typeUsage == null) { throw new InvalidOperationException(string.Format("Type usage for type with name '{0}' is not found.", simpleTypeDescriptor.StoreTypeName)); } } return(model.ProviderManifest.GetStoreType(typeUsage)); }
private static TypeUsage GetTypeUsage(EdmType edmType, SimpleTypeDescriptor simpleTypeDescriptor) { if (edmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType) { PrimitiveType primitiveType = (PrimitiveType)edmType; switch (primitiveType.PrimitiveTypeKind) { case PrimitiveTypeKind.Binary: return(simpleTypeDescriptor.Length.HasValue && simpleTypeDescriptor.Length.Value >= 0 ? TypeUsage.CreateBinaryTypeUsage(primitiveType, simpleTypeDescriptor.IsFixedLength.HasValue && simpleTypeDescriptor.IsFixedLength.Value, simpleTypeDescriptor.Length.Value) : simpleTypeDescriptor.IsFixedLength.HasValue?TypeUsage.CreateBinaryTypeUsage(primitiveType, simpleTypeDescriptor.IsFixedLength.Value) : TypeUsage.CreateDefaultTypeUsage(primitiveType)); case PrimitiveTypeKind.String: return(simpleTypeDescriptor.Length.HasValue && simpleTypeDescriptor.Length.Value >= 0 ? TypeUsage.CreateStringTypeUsage(primitiveType, true, simpleTypeDescriptor.IsFixedLength.HasValue && simpleTypeDescriptor.IsFixedLength.Value, simpleTypeDescriptor.Length.Value) : simpleTypeDescriptor.IsFixedLength.HasValue?TypeUsage.CreateStringTypeUsage(primitiveType, true, simpleTypeDescriptor.IsFixedLength.Value) : TypeUsage.CreateDefaultTypeUsage(primitiveType)); case PrimitiveTypeKind.Decimal: return(simpleTypeDescriptor.Precision.HasValue && simpleTypeDescriptor.Scale.HasValue ? TypeUsage.CreateDecimalTypeUsage(primitiveType, simpleTypeDescriptor.Precision.Value, simpleTypeDescriptor.Scale.Value) : TypeUsage.CreateDefaultTypeUsage(primitiveType)); case PrimitiveTypeKind.DateTimeOffset: return(TypeUsage.CreateDateTimeOffsetTypeUsage(primitiveType, simpleTypeDescriptor.Precision)); case PrimitiveTypeKind.Time: return(TypeUsage.CreateTimeTypeUsage(primitiveType, simpleTypeDescriptor.Precision)); } } return(TypeUsage.CreateDefaultTypeUsage(edmType)); }