/// <summary> /// Given a clrType attempt to return the corresponding target type from /// the worksapce /// </summary> /// <param name="clrType"> The clr type to resolve </param> /// <param name="outTypeUsage"> an out param for the typeUsage to be resolved to </param> /// <returns> true if a TypeUsage can be found for the target type </returns> internal bool TryGetType(Type clrType, out TypeUsage outTypeUsage) { return TryGetTypeByName( clrType.FullNameWithNesting(), false /*ignoreCase*/, out outTypeUsage); }
/// <summary> /// Look up a type in the target data space based upon the fullName /// </summary> /// <param name="fullName"> fullName </param> /// <param name="ignoreCase"> true for case-insensitive lookup </param> /// <param name="typeUsage"> The type usage object to return </param> /// <returns> True if the retrieval succeeded </returns> internal override bool TryGetTypeByName(string fullName, bool ignoreCase, out TypeUsage typeUsage) { typeUsage = null; Map map = null; // From ClrPerspective, we should not allow anything from SSpace. So make sure that the CSpace type does not // have the Target attribute if (MetadataWorkspace.TryGetMap(fullName, DataSpace.OSpace, ignoreCase, DataSpace.OCSpace, out map)) { // Check if it's primitive type, if so, then use the MetadataWorkspace to get the mapped primitive type if (map.EdmItem.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType) { // Reassign the variable with the provider primitive type, then create the type usage var primitiveType = MetadataWorkspace.GetMappedPrimitiveType( ((PrimitiveType)map.EdmItem).PrimitiveTypeKind, DataSpace.CSpace); if (primitiveType != null) { typeUsage = EdmProviderManifest.Instance.GetCanonicalModelTypeUsage(primitiveType.PrimitiveTypeKind); } } else { Debug.Assert(((GlobalItem)map.EdmItem).DataSpace == DataSpace.CSpace); typeUsage = GetMappedTypeUsage(map); } } return (null != typeUsage); }
/// <summary> /// Initializes a new instance of EdmMember class /// </summary> /// <param name="name">name of the member</param> /// <param name="memberTypeUsage">type information containing info about member's type and its facet</param> internal EdmMember(string name, TypeUsage memberTypeUsage) { EntityUtil.CheckStringArgument(name, "name"); EntityUtil.GenericCheckArgumentNull(memberTypeUsage, "memberTypeUsage"); _name = name; _typeUsage = memberTypeUsage; }
private static EdmFunction ResolveCanonicalFunction(string functionName, TypeUsage[] argumentTypes) { Debug.Assert(!string.IsNullOrEmpty(functionName), "Function name must not be null"); List<EdmFunction> functions = new List<EdmFunction>( System.Linq.Enumerable.Where( EdmProviderManifest.Instance.GetStoreFunctions(), func => string.Equals(func.Name, functionName, StringComparison.Ordinal)) ); EdmFunction foundFunction = null; bool ambiguous = false; if (functions.Count > 0) { foundFunction = EntitySql.FunctionOverloadResolver.ResolveFunctionOverloads(functions, argumentTypes, false, out ambiguous); if (ambiguous) { throw EntityUtil.Argument(Strings.Cqt_Function_CanonicalFunction_AmbiguousMatch(functionName)); } } if (foundFunction == null) { throw EntityUtil.Argument(Strings.Cqt_Function_CanonicalFunction_NotFound(functionName)); } return foundFunction; }
/// <summary> /// Initializes a new instance of the class. /// </summary> /// <param name = "type">The data type for this column.</param> /// <param name = "typeUsage"> /// Additional details about the data type. /// This includes details such as maximum length, nullability etc. /// </param> public ColumnModel(PrimitiveTypeKind type, TypeUsage typeUsage) { _type = type; _typeUsage = typeUsage; _clrType = PrimitiveType.GetEdmPrimitiveType(_type).ClrEquivalentType; _clrDefaultValue = CreateDefaultValue(); }
/// <summary> /// Initializes a new instance of the navigation property class /// </summary> /// <param name="name">name of the navigation property</param> /// <param name="typeUsage">TypeUsage object containing the navigation property type and its facets</param> /// <exception cref="System.ArgumentNullException">Thrown if name or typeUsage arguments are null</exception> /// <exception cref="System.ArgumentException">Thrown if name argument is empty string</exception> internal NavigationProperty(string name, TypeUsage typeUsage) : base(name, typeUsage) { EntityUtil.CheckStringArgument(name, "name"); EntityUtil.GenericCheckArgumentNull(typeUsage, "typeUsage"); _accessor = new NavigationPropertyAccessor(name); }
internal static void MapPrimitivePropertyFacets( EdmProperty property, EdmProperty column, TypeUsage typeUsage) { DebugCheck.NotNull(property); DebugCheck.NotNull(column); DebugCheck.NotNull(typeUsage); if (IsValidFacet(typeUsage, XmlConstants.FixedLengthElement)) { column.IsFixedLength = property.IsFixedLength; } if (IsValidFacet(typeUsage, XmlConstants.MaxLengthElement)) { column.IsMaxLength = property.IsMaxLength; column.MaxLength = property.MaxLength; } if (IsValidFacet(typeUsage, XmlConstants.UnicodeElement)) { column.IsUnicode = property.IsUnicode; } if (IsValidFacet(typeUsage, XmlConstants.PrecisionElement)) { column.Precision = property.Precision; } if (IsValidFacet(typeUsage, XmlConstants.ScaleElement)) { column.Scale = property.Scale; } }
private static EdmFunction ResolveCanonicalFunction(string functionName, TypeUsage[] argumentTypes) { DebugCheck.NotEmpty(functionName); var functions = new List<EdmFunction>( EdmProviderManifest.Instance.GetStoreFunctions().Where( func => string.Equals(func.Name, functionName, StringComparison.Ordinal)) ); EdmFunction foundFunction = null; var ambiguous = false; if (functions.Count > 0) { foundFunction = FunctionOverloadResolver.ResolveFunctionOverloads(functions, argumentTypes, false, out ambiguous); if (ambiguous) { throw new ArgumentException(Strings.Cqt_Function_CanonicalFunction_AmbiguousMatch(functionName)); } } if (foundFunction == null) { throw new ArgumentException(Strings.Cqt_Function_CanonicalFunction_NotFound(functionName)); } return foundFunction; }
public override TypeUsage GetEdmType(TypeUsage storeType) { string storeTypeName = storeType.EdmType.Name.ToLower(); PrimitiveType edmPrimitiveType = base.StoreTypeNameToEdmPrimitiveType[storeTypeName]; if (storeTypeName == "string" || storeTypeName == "varchar") { Facet f; int maxLength = -1; if (storeType.Facets.TryGetValue("MaxLength", false, out f) && !f.IsUnbounded && f.Value != null) maxLength = (int)f.Value; if (maxLength != -1) return TypeUsage.CreateStringTypeUsage(edmPrimitiveType, false, false, maxLength); else return TypeUsage.CreateStringTypeUsage(edmPrimitiveType, false, false); } else if (storeTypeName == "decimal" || storeTypeName == "numeric") { Facet f; byte precision = 0; if (storeType.Facets.TryGetValue("Precision", false, out f) && !f.IsUnbounded && f.Value != null) precision = (byte)f.Value; byte scale = 0; if (storeType.Facets.TryGetValue("Scale", false, out f) && !f.IsUnbounded && f.Value != null) scale = (byte)f.Value; if (precision != 0 && scale != 0) return TypeUsage.CreateDecimalTypeUsage(edmPrimitiveType, precision, scale); else return TypeUsage.CreateDecimalTypeUsage(edmPrimitiveType); } else return TypeUsage.CreateDefaultTypeUsage(edmPrimitiveType); throw new NotImplementedException(); }
internal DbUnaryExpression(DbExpressionKind kind, TypeUsage resultType, DbExpression argument) : base(kind, resultType) { DebugCheck.NotNull(argument); _argument = argument; }
internal DbUnaryExpression(DbExpressionKind kind, TypeUsage resultType, DbExpression argument) : base(kind, resultType) { Debug.Assert(argument != null, "DbUnaryExpression.Argument cannot be null"); _argument = argument; }
public override TypeUsage GetEdmType(TypeUsage storeType) { if (storeType == null) { throw new ArgumentNullException("storeType"); } string storeTypeName = storeType.EdmType.Name.ToLowerInvariant(); if (!base.StoreTypeNameToEdmPrimitiveType.ContainsKey(storeTypeName)) { throw new ArgumentException(String.Format("The underlying provider does not support the type '{0}'.", storeTypeName)); } PrimitiveType edmPrimitiveType = base.StoreTypeNameToEdmPrimitiveType[storeTypeName]; if (edmPrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.Binary) { return TypeUsage.CreateBinaryTypeUsage(edmPrimitiveType, false); } if (edmPrimitiveType.PrimitiveTypeKind == PrimitiveTypeKind.String) { Facet facet; if (storeType.Facets.TryGetValue("MaxLength", false, out facet) && !facet.IsUnbounded && facet.Value != null) return TypeUsage.CreateStringTypeUsage(edmPrimitiveType, false, false, (int)facet.Value); else return TypeUsage.CreateStringTypeUsage(edmPrimitiveType, false, false); } return TypeUsage.CreateDefaultTypeUsage(edmPrimitiveType); }
/// <summary> /// The constructor for constructing a CollectionType object with the element type (as a TypeUsage) it contains /// </summary> /// <param name="elementType">The element type that this collection type contains</param> /// <exception cref="System.ArgumentNullException">Thrown if the argument elementType is null</exception> internal CollectionType(TypeUsage elementType) : base(GetIdentity(EntityUtil.GenericCheckArgumentNull(elementType, "elementType")), EdmConstants.TransientNamespace, elementType.EdmType.DataSpace) { _typeUsage = elementType; SetReadOnly(); }
internal DbFunctionAggregate(TypeUsage resultType, DbExpressionList arguments, EdmFunction function, bool isDistinct) : base(resultType, arguments) { Debug.Assert(function != null, "DbFunctionAggregate.Function cannot be null"); _aggregateFunction = function; _distinct = isDistinct; }
// <summary> // Use this constructor if the symbol represents a SqlStatement for which the output columns need to be tracked. // </summary> public Symbol(string name, TypeUsage type, Dictionary<string, Symbol> outputColumns, bool outputColumnsRenamed) { this.name = name; NewName = name; Type = type; this.outputColumns = outputColumns; OutputColumnsRenamed = outputColumnsRenamed; }
/// <summary> /// Initializes a new instance of EdmMember class /// </summary> /// <param name="name"> name of the member </param> /// <param name="memberTypeUsage"> type information containing info about member's type and its facet </param> internal EdmMember(string name, TypeUsage memberTypeUsage) { Check.NotEmpty(name, "name"); Check.NotNull(memberTypeUsage, "memberTypeUsage"); _name = name; _typeUsage = memberTypeUsage; }
internal MetadataEnumMember(string name, TypeUsage enumType, EnumMember enumMember) : base(MetadataMemberClass.EnumMember, name) { Debug.Assert(enumType != null, "enumType must not be null"); Debug.Assert(enumMember != null, "enumMember must not be null"); EnumType = enumType; EnumMember = enumMember; }
/// <summary> /// This method maps the specified storage type and a set of facets for that type /// to an EDM type. /// </summary> /// <param name="storeType"> /// The <see cref="T:System.Data.Metadata.Edm.TypeUsage" /> instance that describes /// a storage type and a set of facets for that type to be mapped to the EDM type. /// </param> /// <returns> /// The <see cref="T:System.Data.Metadata.Edm.TypeUsage" /> instance that describes /// an EDM type and a set of facets for that type. /// </returns> public override TypeUsage GetEdmType(TypeUsage storeType) { string name = storeType.EdmType.Name.ToLowerInvariant(); PrimitiveType edmType = this.StoreTypeNameToEdmPrimitiveType[name]; return ConvertTypeUsage(storeType, edmType); }
/// <summary> /// Use this constructor the symbol represents a SqlStatement with renamed output columns. /// </summary> /// <param name="name"> </param> /// <param name="type"> </param> /// <param name="columns"> </param> public Symbol(string name, TypeUsage type, Dictionary<string, Symbol> columns) { this.name = name; NewName = name; Type = type; this.columns = columns; OutputColumnsRenamed = true; }
internal DbFunctionAggregate(TypeUsage resultType, DbExpressionList arguments, EdmFunction function, bool isDistinct) : base(resultType, arguments) { DebugCheck.NotNull(function); _aggregateFunction = function; _distinct = isDistinct; }
/// <summary> /// Constructs the name of the collection type /// </summary> /// <param name="typeUsage">The typeusage for the element type that this collection type refers to</param> /// <returns>The identity of the resulting collection type</returns> private static string GetIdentity(TypeUsage typeUsage) { StringBuilder builder = new StringBuilder(50); builder.Append("collection["); typeUsage.BuildIdentity(builder); builder.Append("]"); return builder.ToString(); }
// <summary> // Initializes a new instance of the navigation property class // </summary> // <param name="name"> name of the navigation property </param> // <param name="typeUsage"> TypeUsage object containing the navigation property type and its facets </param> // <exception cref="System.ArgumentNullException">Thrown if name or typeUsage arguments are null</exception> // <exception cref="System.ArgumentException">Thrown if name argument is empty string</exception> internal NavigationProperty(string name, TypeUsage typeUsage) : base(name, typeUsage) { Check.NotEmpty(name, "name"); Check.NotNull(typeUsage, "typeUsage"); _accessor = new NavigationPropertyAccessor(name); }
/// <summary> /// The constructor for FunctionParameter taking in a name and a TypeUsage object /// </summary> /// <param name="name">The name of this FunctionParameter</param> /// <param name="typeUsage">The TypeUsage describing the type of this FunctionParameter</param> /// <param name="parameterMode">Mode of the parameter</param> /// <exception cref="System.ArgumentNullException">Thrown if name or typeUsage arguments are null</exception> /// <exception cref="System.ArgumentException">Thrown if name argument is empty string</exception> internal FunctionParameter(string name, TypeUsage typeUsage, ParameterMode parameterMode) { EntityUtil.CheckStringArgument(name, "name"); EntityUtil.GenericCheckArgumentNull(typeUsage, "typeUsage"); _name = name; _typeUsage = typeUsage; SetParameterMode(parameterMode); }
internal MetadataEnumMember(string name, TypeUsage enumType, EnumMember enumMember) : base(MetadataMemberClass.EnumMember, name) { DebugCheck.NotNull(enumType); DebugCheck.NotNull(enumMember); EnumType = enumType; EnumMember = enumMember; }
/// <summary> /// The constructor for FunctionParameter taking in a name and a TypeUsage object /// </summary> /// <param name="name"> The name of this FunctionParameter </param> /// <param name="typeUsage"> The TypeUsage describing the type of this FunctionParameter </param> /// <param name="parameterMode"> Mode of the parameter </param> /// <exception cref="System.ArgumentNullException">Thrown if name or typeUsage arguments are null</exception> /// <exception cref="System.ArgumentException">Thrown if name argument is empty string</exception> internal FunctionParameter(string name, TypeUsage typeUsage, ParameterMode parameterMode) { Check.NotEmpty(name, "name"); Check.NotNull(typeUsage, "typeUsage"); _name = name; _typeUsage = typeUsage; SetParameterMode(parameterMode); }
internal DbBinaryExpression(DbExpressionKind kind, TypeUsage type, DbExpression left, DbExpression right) : base(kind, type) { DebugCheck.NotNull(left); DebugCheck.NotNull(right); _left = left; _right = right; }
internal DbBinaryExpression(DbExpressionKind kind, TypeUsage type, DbExpression left, DbExpression right) : base(kind, type) { Debug.Assert(left != null, "DbBinaryExpression.Left cannot be null"); Debug.Assert(right != null, "DbBinaryExpression.Right cannot be null"); _left = left; _right = right; }
internal DbAggregate(TypeUsage resultType, DbExpressionList arguments) { Debug.Assert(resultType != null, "DbAggregate.ResultType cannot be null"); Debug.Assert(arguments != null, "DbAggregate.Arguments cannot be null"); Debug.Assert(arguments.Count == 1, "DbAggregate requires a single argument"); this._type = resultType; this._args = arguments; }
/// <summary> /// If the passed in TypeUsage has an EdmType that is a PrimitiveType, this method returns /// the corosponding Type object, otherwise it returns the Type object for Object. /// </summary> public Type ClrType(TypeUsage typeUsage) { if (typeUsage.EdmType is PrimitiveType) { return ((PrimitiveType)typeUsage.EdmType).ClrEquivalentType; } return typeof(object); }
// <summary> // The constructor for MetadataProperty taking in a name, a TypeUsage object, and a value for the attribute // </summary> // <param name="name"> The name of this MetadataProperty </param> // <param name="typeUsage"> The TypeUsage describing the type of this MetadataProperty </param> // <param name="value"> The value for this attribute </param> // <exception cref="System.ArgumentNullException">Thrown if typeUsage argument is null</exception> internal MetadataProperty(string name, TypeUsage typeUsage, object value) { Check.NotNull(typeUsage, "typeUsage"); _name = name; _value = value; _typeUsage = typeUsage; _propertyKind = PropertyKind.Extended; }
internal static bool IsSpatialType(this TypeUsage type) { DebugCheck.NotNull(type); return(type.EdmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType && ((PrimitiveType)type.EdmType).IsSpatialType()); }
public void Can_add_get_remove_properties() { var endPropertyMapping = new EndPropertyMapping(); Assert.Empty(endPropertyMapping.PropertyMappings); var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }))); endPropertyMapping.AddPropertyMapping(scalarPropertyMapping); Assert.Same(scalarPropertyMapping, endPropertyMapping.PropertyMappings.Single()); endPropertyMapping.RemovePropertyMapping(scalarPropertyMapping); Assert.Empty(endPropertyMapping.PropertyMappings); }
internal static int GetMaxLength(this TypeUsage type) { DebugCheck.NotNull(type); return(type.GetFacetValue <int>(DbProviderManifest.MaxLengthFacetName)); }
internal static ReadOnlyMetadataCollection <EdmProperty> GetProperties(TypeUsage typeUsage) { return(GetProperties(typeUsage.EdmType)); }
// <summary> // Reusing TypeUsage and FieldMetadata from another EntityRecordInfo which has all the same info // but with a different EntityKey instance. // </summary> internal DataRecordInfo(DataRecordInfo recordInfo) { _fieldMetadata = recordInfo._fieldMetadata; _metadata = recordInfo._metadata; }
internal static PrimitiveTypeKind GetPrimitiveTypeKind(this TypeUsage type) { DebugCheck.NotNull(type); return(((PrimitiveType)type.EdmType).PrimitiveTypeKind); }
public void CreateForeignKeyOperation() { var migrationOperations = new List <MigrationOperation>(); // create dependant table Posts var createTableOperation = CreateTableOperation(); migrationOperations.Add(createTableOperation); // Add column BlogId to create the constraints if (ProviderManifest == null) { ProviderManifest = new MySqlProviderManifest(st.Version.ToString()); } TypeUsage tu = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)); TypeUsage result = ProviderManifest.GetStoreType(tu); var intColumn = new ColumnModel(PrimitiveTypeKind.Int32, result) { Name = "BlogId", IsNullable = false }; var addColumnMigratioOperation = new AddColumnOperation("Posts", intColumn); migrationOperations.Add(addColumnMigratioOperation); // create constrain object var createForeignkeyOperation = new AddForeignKeyOperation(); createForeignkeyOperation.Name = "FKBlogs"; createForeignkeyOperation.DependentTable = "Posts"; createForeignkeyOperation.DependentColumns.Add("BlogId"); createForeignkeyOperation.CascadeDelete = true; createForeignkeyOperation.PrincipalTable = "Blogs"; createForeignkeyOperation.PrincipalColumns.Add("BlogId"); //create index to use migrationOperations.Add(createForeignkeyOperation.CreateCreateIndexOperation()); migrationOperations.Add(createForeignkeyOperation); using (BlogContext context = new BlogContext()) { if (context.Database.Exists()) { context.Database.Delete(); } context.Database.Create(); Assert.Equal(true, GenerateAndExecuteMySQLStatements(migrationOperations)); using (var conn = new MySqlConnection(context.Database.Connection.ConnectionString)) { if (conn.State == System.Data.ConnectionState.Closed) { conn.Open(); } // check for foreign key creation MySqlCommand query = new MySqlCommand("select Count(*) from information_schema.table_constraints where constraint_type = 'foreign key' and constraint_schema = '" + conn.Database + "' and constraint_name = 'FKBlogs'", conn); int rows = Convert.ToInt32(query.ExecuteScalar()); Assert.Equal(1, rows); // check for table creation query = new MySqlCommand("select Count(*) from information_schema.Tables WHERE `table_name` = 'Posts' and `table_schema` = '" + conn.Database + "' ", conn); rows = Convert.ToInt32(query.ExecuteScalar()); Assert.Equal(1, rows); conn.Close(); } // Test fix for MySqlConnection con = GetConnectionFromContext(context); con.Open(); try { MySqlCommand cmd = new MySqlCommand("show create table `posts`", con); using (MySqlDataReader r = cmd.ExecuteReader()) { r.Read(); string sql = r.GetString(1); Assert.True(sql.IndexOf( " CONSTRAINT `FKBlogs` FOREIGN KEY (`BlogId`) REFERENCES `blogs` (`BlogId`) ON DELETE CASCADE ON UPDATE CASCADE", StringComparison.OrdinalIgnoreCase) != -1); } } finally { con.Close(); } } }
/// <summary> /// Determines SqlDbType for the given primitive type. Extracts facet /// information as well. /// </summary> private static SqlDbType GetSqlDbType(TypeUsage type, out int?size, out byte?precision, out byte?scale) { // only supported for primitive type var primitiveTypeKind = TypeSemantics.GetPrimitiveTypeKind(type); size = default(int?); precision = default(byte?); scale = default(byte?); // CONSIDER(CMeek):: add logic for Xml here switch (primitiveTypeKind) { case PrimitiveTypeKind.Binary: // for output parameters, ensure there is space... size = GetParameterSize(type); return(GetBinaryDbType(type)); case PrimitiveTypeKind.Boolean: return(SqlDbType.Bit); case PrimitiveTypeKind.Byte: return(SqlDbType.TinyInt); case PrimitiveTypeKind.Time: throw ADP1.NotSupported(EntityRes.GetString(EntityRes.ProviderDoesNotSupportType, "Time")); case PrimitiveTypeKind.DateTimeOffset: throw ADP1.NotSupported(EntityRes.GetString(EntityRes.ProviderDoesNotSupportType, "DateTimeOffset")); case PrimitiveTypeKind.DateTime: return(SqlDbType.DateTime); case PrimitiveTypeKind.Decimal: precision = GetParameterPrecision(type, null); scale = GetScale(type); return(SqlDbType.Decimal); case PrimitiveTypeKind.Double: return(SqlDbType.Float); case PrimitiveTypeKind.Guid: return(SqlDbType.UniqueIdentifier); case PrimitiveTypeKind.Int16: return(SqlDbType.SmallInt); case PrimitiveTypeKind.Int32: return(SqlDbType.Int); case PrimitiveTypeKind.Int64: return(SqlDbType.BigInt); case PrimitiveTypeKind.SByte: return(SqlDbType.SmallInt); case PrimitiveTypeKind.Single: return(SqlDbType.Real); case PrimitiveTypeKind.String: size = GetParameterSize(type); return(GetStringDbType(type)); default: Debug.Fail("unknown PrimitiveTypeKind " + primitiveTypeKind); return(SqlDbType.Variant); } }
/// <summary> /// Constructs a SqlCeParameter /// </summary> /// <param name="queryParameter"> </param> /// <returns> </returns> internal static DbParameter CreateSqlCeParameter( string name, TypeUsage type, object value, bool ignoreMaxLengthFacet, bool isLocalProvider) { var rdpSqlCeParameter = Type.GetType(RemoteProvider.SqlCeParameter); // No other parameter type is supported. // DebugCheck.NotNull(type); int? size; byte?precision; byte?scale; var result = isLocalProvider ? new SqlCeParameter() : (DbParameter)RemoteProviderHelper.CreateRemoteProviderType(RemoteProvider.SqlCeParameter); result.ParameterName = name; result.Value = value; // .Direction // parameter.Direction - take the default. we don't support output parameters. result.Direction = ParameterDirection.Input; // .Size, .Precision, .Scale and .SqlDbType var sqlDbType = GetSqlDbType(type, out size, out precision, out scale); // Skip guessing the parameter type (only for strings & blobs) if parameter size is not available // Instead, let QP take proper guess at execution time with available details. // if ((null != size) || (!TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.String) && !TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Binary))) { if (isLocalProvider) { var sqlCeParameter = (SqlCeParameter)result; if (sqlCeParameter.SqlDbType != sqlDbType) { sqlCeParameter.SqlDbType = sqlDbType; } } else { // Remote Provider is loaded by reflection. As SqlDbType is not part of the base interface // We need to access this using reflection only. var rdpType = RemoteProviderHelper.GetRemoteProviderType(RemoteProvider.SqlCeParameter); var rdpInfo = rdpType.GetProperty("SqlDbType"); rdpInfo.SetValue(result, sqlDbType, null); } } // Note that we overwrite 'facet' parameters where either the value is different or // there is an output parameter. This is because output parameters in SqlClient have their // facets clobbered if they are implicitly set (e.g. if the Precision was implicitly set // by setting the value) if (!ignoreMaxLengthFacet && size.HasValue && (result.Size != size.Value)) { result.Size = size.Value; } if (precision.HasValue && (((IDbDataParameter)result).Precision != precision.Value)) { ((IDbDataParameter)result).Precision = precision.Value; } if (scale.HasValue && (((IDbDataParameter)result).Scale != scale.Value)) { ((IDbDataParameter)result).Scale = scale.Value; } // .IsNullable var isNullable = TypeSemantics.IsNullable(type); if (isNullable != result.IsNullable) { result.IsNullable = isNullable; } return(result); }
public abstract TypeUsage GetEdmType(TypeUsage storeType);
internal DbCastExpression(TypeUsage type, DbExpression argument) : base(DbExpressionKind.Cast, type, argument) { }
// <summary> // Create expression to read a column value with error handling // </summary> internal static Expression Emit_Shaper_GetColumnValueWithErrorHandling(Type resultType, int ordinal, TypeUsage columnType) { // shaper.GetSpatialColumnValueWithErrorHandling(ordinal, primitiveColumnType) OR shaper.GetColumnValueWithErrorHandling(ordinal) Expression result; PrimitiveTypeKind primitiveColumnType; if (Helper.IsSpatialType(columnType, out primitiveColumnType)) { primitiveColumnType = Helper.IsGeographicType((PrimitiveType)columnType.EdmType) ? PrimitiveTypeKind.Geography : PrimitiveTypeKind.Geometry; result = Expression.Call( Shaper_Parameter, Shaper_GetSpatialColumnValueWithErrorHandling.MakeGenericMethod(resultType), Expression.Constant(ordinal), Expression.Constant(primitiveColumnType, typeof(PrimitiveTypeKind))); } else { result = Expression.Call( Shaper_Parameter, Shaper_GetColumnValueWithErrorHandling.MakeGenericMethod(resultType), Expression.Constant(ordinal)); } return(result); }
internal MetadataEnumMember(string name, TypeUsage enumType, EnumMember enumMember) : base(MetadataMemberClass.EnumMember, name) { this.EnumType = enumType; this.EnumMember = enumMember; }
internal NewEntityOp(TypeUsage type, List <RelProperty> relProperties, bool scoped, EntitySet entitySet) : base(OpType.NewEntity, type, scoped, entitySet, relProperties) { }
internal static bool MustFacetBeConstant(this TypeUsage type, string facetName) { DebugCheck.NotNull(type); return(((PrimitiveType)type.EdmType).FacetDescriptions.Single(f => f.FacetName == facetName).IsConstant); }
internal EntityCommandDefinition( DbProviderFactory storeProviderFactory, DbCommandTree commandTree, DbInterceptionContext interceptionContext, IDbDependencyResolver resolver = null, BridgeDataReaderFactory bridgeDataReaderFactory = null, ColumnMapFactory columnMapFactory = null) { this._bridgeDataReaderFactory = bridgeDataReaderFactory ?? new BridgeDataReaderFactory((Translator)null); this._columnMapFactory = columnMapFactory ?? new ColumnMapFactory(); this._storeProviderServices = (resolver != null ? resolver.GetService <DbProviderServices>((object)storeProviderFactory.GetProviderInvariantName()) : (DbProviderServices)null) ?? storeProviderFactory.GetProviderServices(); try { if (commandTree.CommandTreeKind == DbCommandTreeKind.Query) { List <ProviderCommandInfo> providerCommands = new List <ProviderCommandInfo>(); ColumnMap resultColumnMap; int columnCount; System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Compile(commandTree, out providerCommands, out resultColumnMap, out columnCount, out this._entitySets); this._columnMapGenerators = new EntityCommandDefinition.IColumnMapGenerator[1] { (EntityCommandDefinition.IColumnMapGenerator) new EntityCommandDefinition.ConstantColumnMapGenerator(resultColumnMap, columnCount) }; this._mappedCommandDefinitions = new List <DbCommandDefinition>(providerCommands.Count); foreach (ProviderCommandInfo providerCommandInfo in providerCommands) { DbCommandDefinition commandDefinition = this._storeProviderServices.CreateCommandDefinition(providerCommandInfo.CommandTree, interceptionContext); if (commandDefinition == null) { throw new ProviderIncompatibleException(Strings.ProviderReturnedNullForCreateCommandDefinition); } this._mappedCommandDefinitions.Add(commandDefinition); } } else { DbFunctionCommandTree functionCommandTree = (DbFunctionCommandTree)commandTree; FunctionImportMappingNonComposable targetFunctionMapping = EntityCommandDefinition.GetTargetFunctionMapping(functionCommandTree); IList <FunctionParameter> returnParameters = (IList <FunctionParameter>)functionCommandTree.EdmFunction.ReturnParameters; int length = returnParameters.Count > 1 ? returnParameters.Count : 1; this._columnMapGenerators = new EntityCommandDefinition.IColumnMapGenerator[length]; TypeUsage storeResultType = this.DetermineStoreResultType(targetFunctionMapping, 0, out this._columnMapGenerators[0]); for (int resultSetIndex = 1; resultSetIndex < length; ++resultSetIndex) { this.DetermineStoreResultType(targetFunctionMapping, resultSetIndex, out this._columnMapGenerators[resultSetIndex]); } List <KeyValuePair <string, TypeUsage> > keyValuePairList = new List <KeyValuePair <string, TypeUsage> >(); foreach (KeyValuePair <string, TypeUsage> parameter in functionCommandTree.Parameters) { keyValuePairList.Add(parameter); } this._mappedCommandDefinitions = new List <DbCommandDefinition>(1) { this._storeProviderServices.CreateCommandDefinition((DbCommandTree) new DbFunctionCommandTree(functionCommandTree.MetadataWorkspace, DataSpace.SSpace, targetFunctionMapping.TargetFunction, storeResultType, (IEnumerable <KeyValuePair <string, TypeUsage> >)keyValuePairList)) }; if (targetFunctionMapping.FunctionImport.EntitySets.FirstOrDefault <EntitySet>() != null) { this._entitySets = new Set <EntitySet>(); this._entitySets.Add(targetFunctionMapping.FunctionImport.EntitySets.FirstOrDefault <EntitySet>()); this._entitySets.MakeReadOnly(); } } List <EntityParameter> entityParameterList = new List <EntityParameter>(); foreach (KeyValuePair <string, TypeUsage> parameter in commandTree.Parameters) { EntityParameter fromQueryParameter = EntityCommandDefinition.CreateEntityParameterFromQueryParameter(parameter); entityParameterList.Add(fromQueryParameter); } this._parameters = new ReadOnlyCollection <EntityParameter>((IList <EntityParameter>)entityParameterList); } catch (EntityCommandCompilationException ex) { throw; } catch (Exception ex) { if (ex.IsCatchableExceptionType()) { throw new EntityCommandCompilationException(Strings.EntityClient_CommandDefinitionPreparationFailed, ex); } throw; } }
internal static byte GetScale(this TypeUsage type) { DebugCheck.NotNull(type); return(type.GetFacetValue <byte>(DbProviderManifest.ScaleFacetName)); }
internal static bool TryGetEdmType <TEdmType>(TypeUsage typeUsage, out TEdmType type) where TEdmType : EdmType { type = typeUsage.EdmType as TEdmType; return(type != null); }
internal static bool IsPrimitiveType(this TypeUsage type) { // Null type okay--returns false return(type != null && type.EdmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType); }
public abstract TypeUsage GetStoreType(TypeUsage edmType);
internal DbRefExpression(TypeUsage refResultType, EntitySet entitySet, DbExpression refKeys) : base(DbExpressionKind.Ref, refResultType, refKeys) { this._entitySet = entitySet; }
// <summary> // Retrieves Properties and/or RelationshipEnds declared by (and ONLY by) the specified type. // </summary> internal static IEnumerable GetDeclaredStructuralMembers(TypeUsage type) { return(GetDeclaredStructuralMembers(type.EdmType)); }
internal static TEdmType GetEdmType <TEdmType>(TypeUsage typeUsage) where TEdmType : EdmType { return((TEdmType)typeUsage.EdmType); }
// <summary> // Factory method for creating a type usage for underlying union type of spatial type usage. // </summary> // <param name="spatialTypeUsage"> Spatial type usage used to create a union type usage of. </param> // <returns> Type usage for the spatial union type of the correct topology. </returns> internal static TypeUsage CreateSpatialUnionTypeUsage(TypeUsage spatialTypeUsage) { DebugCheck.NotNull(spatialTypeUsage); Debug.Assert(TypeSemantics.IsStrongSpatialType(spatialTypeUsage), "spatialTypeUsage is not a strong spatial type"); return(TypeUsage.Create(Helper.GetSpatialNormalizedPrimitiveType(spatialTypeUsage.EdmType), spatialTypeUsage.Facets)); }
internal static bool IsPrimitiveType(this TypeUsage type, PrimitiveTypeKind primitiveTypeKind) { // Null type okay--returns false return(type.IsPrimitiveType() && ((PrimitiveType)type.EdmType).PrimitiveTypeKind == primitiveTypeKind); }
public void Cannot_remove_property_when_read_only() { var associationEnd = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace)); var mapping = new EndPropertyMapping(associationEnd); var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }))); mapping.AddPropertyMapping(scalarPropertyMapping); mapping.SetReadOnly(); Assert.True(mapping.IsReadOnly); Assert.Equal( Strings.OperationOnReadOnlyItem, Assert.Throws <InvalidOperationException>( () => mapping.RemovePropertyMapping(scalarPropertyMapping)).Message); }
// // Type extractors // // <summary> // Retrieves Properties and/or RelationshipEnds declared by the specified type or any base type. // </summary> internal static IBaseList <EdmMember> GetAllStructuralMembers(TypeUsage type) { return(GetAllStructuralMembers(type.EdmType)); }
internal static T GetFacetValue <T>(this TypeUsage type, string facetName) { DebugCheck.NotNull(type); return((T)type.Facets[facetName].Value); }
internal ElementOp(TypeUsage type) : base(OpType.Element, type) { }
public void SetReadOnly_is_called_on_child_mapping_items() { var associationEnd = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace)); var mapping = new EndPropertyMapping(associationEnd); var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }))); mapping.AddPropertyMapping(scalarPropertyMapping); Assert.False(scalarPropertyMapping.IsReadOnly); mapping.SetReadOnly(); Assert.True(scalarPropertyMapping.IsReadOnly); }