/// <summary> /// Given an entity command, store provider command and a connection, sets all output parameter values on the entity command. /// The connection is used to determine how to map spatial values. /// </summary> /// <param name="entityCommand">Entity command on which to set parameter values. Must not be null.</param> /// <param name="storeProviderCommand">Store provider command from which to retrieve parameter values. Must not /// be null.</param> /// <param name="connection">The connection on which the command was run. Must not be null</param> internal static void SetEntityParameterValues(EntityCommand entityCommand, DbCommand storeProviderCommand, EntityConnection connection) { Debug.Assert(null != entityCommand); Debug.Assert(null != storeProviderCommand); Debug.Assert(null != connection); foreach (DbParameter storeParameter in storeProviderCommand.Parameters) { ParameterDirection direction = storeParameter.Direction; if (0 != (direction & ParameterDirection.Output)) { // if the entity command also defines the parameter, propagate store parameter value // to entity parameter int parameterOrdinal = entityCommand.Parameters.IndexOf(storeParameter.ParameterName); if (0 <= parameterOrdinal) { EntityParameter entityParameter = entityCommand.Parameters[parameterOrdinal]; object parameterValue = storeParameter.Value; TypeUsage parameterType = entityParameter.GetTypeUsage(); if (Helper.IsSpatialType(parameterType)) { parameterValue = GetSpatialValueFromProviderValue(parameterValue, (PrimitiveType)parameterType.EdmType, connection); } entityParameter.Value = parameterValue; } } } }
/// <summary> /// Updates storeParameter size, precision and scale properties from user provided parameter properties. /// </summary> /// <param name="entityParameter"> </param> /// <param name="storeParameter"> </param> private static void SyncParameterProperties( EntityParameter entityParameter, DbParameter storeParameter, DbProviderServices storeProviderServices) { IDbDataParameter dbDataParameter = storeParameter; // DBType is not currently syncable; it's part of the cache key anyway; this is because we can't guarantee // that the store provider will honor it -- (SqlClient doesn't...) //if (entityParameter.IsDbTypeSpecified) //{ // storeParameter.DbType = entityParameter.DbType; //} // Give the store provider the opportunity to set the value before any parameter state has been copied from // the EntityParameter. var parameterTypeUsage = TypeHelpers.GetPrimitiveTypeUsageForScalar(entityParameter.GetTypeUsage()); storeProviderServices.SetParameterValue(storeParameter, parameterTypeUsage, entityParameter.Value); // Override the store provider parameter state with any explicitly specified values from the EntityParameter. if (entityParameter.IsDirectionSpecified) { storeParameter.Direction = entityParameter.Direction; } if (entityParameter.IsIsNullableSpecified) { storeParameter.IsNullable = entityParameter.IsNullable; } if (entityParameter.IsSizeSpecified) { storeParameter.Size = entityParameter.Size; } if (entityParameter.IsPrecisionSpecified) { dbDataParameter.Precision = entityParameter.Precision; } if (entityParameter.IsScaleSpecified) { dbDataParameter.Scale = entityParameter.Scale; } }
internal static void SetEntityParameterValues( EntityCommand entityCommand, DbCommand storeProviderCommand, EntityConnection connection) { foreach (DbParameter parameter1 in storeProviderCommand.Parameters) { if ((parameter1.Direction & ParameterDirection.Output) != (ParameterDirection)0) { int index = entityCommand.Parameters.IndexOf(parameter1.ParameterName); if (0 <= index) { EntityParameter parameter2 = entityCommand.Parameters[index]; object fromProviderValue = parameter1.Value; TypeUsage typeUsage = parameter2.GetTypeUsage(); if (Helper.IsSpatialType(typeUsage)) { fromProviderValue = CommandHelper.GetSpatialValueFromProviderValue(fromProviderValue, (PrimitiveType)typeUsage.EdmType, connection); } parameter2.Value = fromProviderValue; } } } }
/// <summary> /// Updates storeParameter size, precision and scale properties from user provided parameter properties. /// </summary> private static void SyncParameterProperties( EntityParameter entityParameter, DbParameter storeParameter, DbProviderServices storeProviderServices) { IDbDataParameter dbDataParameter = storeParameter; // DBType is not currently syncable; it's part of the cache key anyway; this is because we can't guarantee // that the store provider will honor it -- (SqlClient doesn't...) //if (entityParameter.IsDbTypeSpecified) //{ // storeParameter.DbType = entityParameter.DbType; //} // Give the store provider the opportunity to set the value before any parameter state has been copied from // the EntityParameter. var parameterTypeUsage = TypeHelpers.GetPrimitiveTypeUsageForScalar(entityParameter.GetTypeUsage()); storeProviderServices.SetParameterValue(storeParameter, parameterTypeUsage, entityParameter.Value); // Override the store provider parameter state with any explicitly specified values from the EntityParameter. if (entityParameter.IsDirectionSpecified) { storeParameter.Direction = entityParameter.Direction; } if (entityParameter.IsIsNullableSpecified) { storeParameter.IsNullable = entityParameter.IsNullable; } if (entityParameter.IsSizeSpecified) { storeParameter.Size = entityParameter.Size; } if (entityParameter.IsPrecisionSpecified) { dbDataParameter.Precision = entityParameter.Precision; } if (entityParameter.IsScaleSpecified) { dbDataParameter.Scale = entityParameter.Scale; } }
private static void SyncParameterProperties( EntityParameter entityParameter, DbParameter storeParameter, DbProviderServices storeProviderServices) { IDbDataParameter dbDataParameter = (IDbDataParameter)storeParameter; TypeUsage typeUsageForScalar = TypeHelpers.GetPrimitiveTypeUsageForScalar(entityParameter.GetTypeUsage()); storeProviderServices.SetParameterValue(storeParameter, typeUsageForScalar, entityParameter.Value); if (entityParameter.IsDirectionSpecified) { storeParameter.Direction = entityParameter.Direction; } if (entityParameter.IsIsNullableSpecified) { storeParameter.IsNullable = entityParameter.IsNullable; } if (entityParameter.IsSizeSpecified) { storeParameter.Size = entityParameter.Size; } if (entityParameter.IsPrecisionSpecified) { dbDataParameter.Precision = entityParameter.Precision; } if (!entityParameter.IsScaleSpecified) { return; } dbDataParameter.Scale = entityParameter.Scale; }