EntityParameter.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / EntityClient / EntityParameter.cs / 1 / EntityParameter.cs

                            //---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner  [....], [....]
//--------------------------------------------------------------------- 
using System.Collections.Generic; 
using System.Text;
using System.Data; 
using System.Data.Common;
using System.Data.Common.CommandTrees;
using System.Data.Metadata.Edm;
using System.Text.RegularExpressions; 
using System.Diagnostics;
 
namespace System.Data.EntityClient 
{
    ///  
    /// Class representing a parameter used in EntityCommand
    /// 
    public sealed partial class EntityParameter : DbParameter, IDbDataParameter
    { 
        private string _parameterName;
        private DbType? _dbType; 
        private byte? _precision; 
        private byte? _scale;
        private bool _isDirty; 

        /// 
        /// Constructs the EntityParameter object
        ///  
        public EntityParameter()
        { 
        } 

        ///  
        /// Constructs the EntityParameter object with the given parameter name and the type of the parameter
        /// 
        /// The name of the parameter
        /// The type of the parameter 
        public EntityParameter(string parameterName, DbType dbType)
        { 
            SetParameterNameWithValidation(parameterName, "parameterName"); 
            this.DbType = dbType;
        } 

        /// 
        /// Constructs the EntityParameter object with the given parameter name, the type of the parameter, and the size of the
        /// parameter 
        /// 
        /// The name of the parameter 
        /// The type of the parameter 
        /// The size of the parameter
        public EntityParameter(string parameterName, DbType dbType, int size) 
        {
            SetParameterNameWithValidation(parameterName, "parameterName");
            this.DbType = dbType;
            this.Size = size; 
        }
 
        ///  
        /// Constructs the EntityParameter object with the given parameter name, the type of the parameter, the size of the
        /// parameter, and the name of the source column 
        /// 
        /// The name of the parameter
        /// The type of the parameter
        /// The size of the parameter 
        /// The name of the source column mapped to the data set, used for loading the parameter value
        public EntityParameter(string parameterName, DbType dbType, int size, string sourceColumn) 
        { 
            SetParameterNameWithValidation(parameterName, "parameterName");
            this.DbType = dbType; 
            this.Size = size;
            this.SourceColumn = sourceColumn;
        }
 
        /// 
        /// Constructs the EntityParameter object with the given parameter name, the type of the parameter, the size of the 
        /// parameter, and the name of the source column 
        /// 
        /// The name of the parameter 
        /// The type of the parameter
        /// The size of the parameter
        /// The direction of the parameter, whether it's input/output/both/return value
        /// If the parameter is nullable 
        /// The floating point precision of the parameter, valid only if the parameter type is a floating point type
        /// The scale of the parameter, valid only if the parameter type is a floating point type 
        /// The name of the source column mapped to the data set, used for loading the parameter value 
        /// The data row version to use when loading the parameter value
        /// The value of the parameter 
        public EntityParameter(string parameterName,
                            DbType dbType,
                            int size,
                            ParameterDirection direction, 
                            bool isNullable,
                            byte precision, 
                            byte scale, 
                            string sourceColumn,
                            DataRowVersion sourceVersion, 
                            object value)
        {
            SetParameterNameWithValidation(parameterName, "parameterName");
            this.DbType = dbType; 
            this.Size = size;
            this.Direction = direction; 
            this.IsNullable = isNullable; 
            this.Precision = precision;
            this.Scale = scale; 
            this.SourceColumn = sourceColumn;
            this.SourceVersion = sourceVersion;
            this.Value = value;
        } 

        ///  
        /// The name of the parameter 
        /// 
        public override string ParameterName 
        {
            get
            {
                return this._parameterName ?? ""; 
            }
            set 
            { 
                SetParameterNameWithValidation(value, "value");
            } 
        }

        /// 
        /// Helper method to validate the parameter name; Ideally we'd only call this once, but 
        /// we have to put an argumentName on the Argument exception, and the property setter would
        /// need "value" which confuses folks when they call the constructor that takes the value 
        /// of the parameter.  c'est la vie. 
        /// 
        ///  
        /// 
        private void SetParameterNameWithValidation(string parameterName, string argumentName)
        {
            if (!string.IsNullOrEmpty(parameterName) && !DbCommandTree.IsValidParameterName(parameterName)) 
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.EntityClient_InvalidParameterName(parameterName), argumentName); 
            } 
            PropertyChanging();
            this._parameterName = parameterName; 
        }

        /// 
        /// The type of the parameter 
        /// 
        public override DbType DbType 
        { 
            get
            { 
                // If the user hasn't set the DbType, then we deduce it from the value, but we won't set it in the
                // member field as it's used to keep track of what the user set explicitly
                if (!this._dbType.HasValue)
                { 
                    // If we can't deduce the type as there are no values, just assume it's string type
                    if (_value == null) 
                        return DbType.String; 

                    try 
                    {
                        return TypeHelpers.ConvertClrTypeToDbType(_value.GetType());
                    }
                    catch (ArgumentException e) 
                    {
                        throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.EntityClient_CannotDeduceDbType, e); 
                    } 
                }
 
                return (DbType)this._dbType;
            }
            set
            { 
                PropertyChanging();
                this._dbType = value; 
            } 
        }
 
        /// 
        /// The precision of the parameter if the parameter is a floating point type
        /// 
        public byte Precision 
        {
            get 
            { 
                byte result = this._precision.HasValue ? this._precision.Value : (byte)0;
                return result; 
            }
            set
            {
                PropertyChanging(); 
                this._precision = value;
            } 
        } 

        ///  
        /// The scale of the parameter if the parameter is a floating point type
        /// 
        public byte Scale
        { 
            get
            { 
                byte result = this._scale.HasValue ? this._scale.Value : (byte)0; 
                return result;
            } 
            set
            {
                PropertyChanging();
                this._scale = value; 
            }
        } 
 
        /// 
        /// The value of the parameter 
        /// 
        public override object Value
        {
            get 
            {
                return this._value; 
            } 
            set
            { 
                // If the user hasn't set the DbType, then we have to figure out if the DbType will change as a result
                // of the change in the value.  What we want to achieve is that changes to the value will not cause
                // it to be dirty, but changes to the value that causes the apparent DbType to change, then should be
                // dirty. 
                if (!this._dbType.HasValue)
                { 
                    // If the value is null, then we assume it's string type 
                    DbType oldDbType = DbType.String;
                    if (_value != null) 
                    {
                        oldDbType = TypeHelpers.ConvertClrTypeToDbType(_value.GetType());
                    }
 
                    // If the value is null, then we assume it's string type
                    DbType newDbType = DbType.String; 
                    if (value != null) 
                    {
                        newDbType = TypeHelpers.ConvertClrTypeToDbType(value.GetType()); 
                    }

                    if (oldDbType != newDbType)
                    { 
                        PropertyChanging();
                    } 
                } 

                this._value = value; 
            }
        }

        ///  
        /// Gets whether this collection has been changes since the last reset
        ///  
        internal bool IsDirty 
        {
            get 
            {
                return _isDirty;
            }
        } 

        ///  
        /// Indicates whether the DbType property has been set by the user; 
        /// 
        internal bool IsDbTypeSpecified 
        {
            get
            {
                return this._dbType.HasValue; 
            }
        } 
 
        /// 
        /// Indicates whether the Direction property has been set by the user; 
        /// 
        internal bool IsDirectionSpecified
        {
            get 
            {
                return this._direction != 0; 
            } 
        }
 
        /// 
        /// Indicates whether the IsNullable property has been set by the user;
        /// 
        internal bool IsIsNullableSpecified 
        {
            get 
            { 
                return this._isNullable.HasValue;
            } 
        }

        /// 
        /// Indicates whether the Precision property has been set by the user; 
        /// 
        internal bool IsPrecisionSpecified 
        { 
            get
            { 
                return this._precision.HasValue;
            }
        }
 
        /// 
        /// Indicates whether the Scale property has been set by the user; 
        ///  
        internal bool IsScaleSpecified
        { 
            get
            {
                return this._scale.HasValue;
            } 
        }
 
        ///  
        /// Indicates whether the Size property has been set by the user;
        ///  
        internal bool IsSizeSpecified
        {
            get
            { 
                return this._size.HasValue;
            } 
        } 

        ///  
        /// Resets the DbType property to its original settings
        /// 
        public override void ResetDbType()
        { 
            if (_dbType != null)
            { 
                PropertyChanging(); 
            }
 
            _dbType = null;
        }

        ///  
        /// Clones this parameter object
        ///  
        /// The new cloned object 
        internal EntityParameter Clone()
        { 
            return new EntityParameter(this);
        }

        ///  
        /// Clones this parameter object
        ///  
        /// The new cloned object 
        private void CloneHelper(EntityParameter destination)
        { 
            CloneHelperCore(destination);

            destination._parameterName = _parameterName;
            destination._dbType = _dbType; 
            destination._precision = _precision;
            destination._scale = _scale; 
        } 

        ///  
        /// Marks that this parameter has been changed
        /// 
        private void PropertyChanging()
        { 
            _isDirty = true;
        } 
 
        /// 
        /// Determines the size of the given object 
        /// 
        /// 
        /// 
        private int ValueSize(object value) 
        {
            return ValueSizeCore(value); 
        } 

        ///  
        /// Get the type usage for this parameter
        /// 
        /// The metadata workspace to where the type metadata is retrieved
        /// The type usage for this parameter 
        //NOTE: Because GetTypeUsage throws CommandValidationExceptions, it should only be called from EntityCommand during command execution
        internal TypeUsage GetTypeUsage(MetadataWorkspace metadataWorkspace) 
        { 
            FacetValues values = null;
 
            DbType dbType = this.DbType;
            PrimitiveTypeKind primitiveTypeKind = PrimitiveTypeKind.String;
            switch (dbType)
            { 
                case DbType.AnsiString:
                    values = new FacetValues { Unicode = false, FixedLength = false, MaxLength = (int?)null }; 
                    primitiveTypeKind = PrimitiveTypeKind.String; 
                    break;
 
                case DbType.AnsiStringFixedLength:
                    values = new FacetValues { Unicode = false, FixedLength = true, MaxLength = (int?)null };
                    primitiveTypeKind = PrimitiveTypeKind.String;
                    break; 

                case DbType.String: 
                    values = new FacetValues { Unicode = true, FixedLength = false, MaxLength = (int?)null }; 
                    primitiveTypeKind = PrimitiveTypeKind.String;
                    break; 

                case DbType.StringFixedLength:
                    values = new FacetValues { Unicode = true, FixedLength = true, MaxLength = (int?)null };
                    primitiveTypeKind = PrimitiveTypeKind.String; 
                    break;
 
                case DbType.Xml: 
                    // SQLBUDT #514204 - EntityCommand: XML parameter size must be ignored
                    /* XML parameters must not have a explicit size */ 
                    values = new FacetValues { Unicode = true, FixedLength = false, MaxLength = (int?)null };
                    primitiveTypeKind = PrimitiveTypeKind.String;
                    break;
 
                case DbType.Binary:
                    values = new FacetValues { MaxLength = (int?)null }; 
                    primitiveTypeKind = PrimitiveTypeKind.Binary; 
                    break;
 
                case DbType.Boolean:
                    primitiveTypeKind = PrimitiveTypeKind.Boolean;
                    break;
 
                case DbType.Byte:
                    primitiveTypeKind = PrimitiveTypeKind.Byte; 
                    break; 

                case DbType.DateTime: 
                case DbType.Date:
                    primitiveTypeKind = PrimitiveTypeKind.DateTime;
                    break;
 
                case DbType.DateTime2:
                    primitiveTypeKind = PrimitiveTypeKind.DateTime; 
                    values = new FacetValues { Precision = (byte?)null }; 
                    break;
 
                case DbType.Time:
                    primitiveTypeKind = PrimitiveTypeKind.Time;
                    values = new FacetValues { Precision = (byte?)null };
                    break; 

                case DbType.DateTimeOffset: 
                    primitiveTypeKind = PrimitiveTypeKind.DateTimeOffset; 
                    values = new FacetValues { Precision = (byte?)null };
                    break; 

                // For decimal and money, in the case of precision == 0, we don't want any facets when picking the type so the
                // default type should be picked
                case DbType.Decimal: 
                // SQLBU 480928: Need to make currency a separate case once we enable money type
                case DbType.Currency: 
                    primitiveTypeKind = PrimitiveTypeKind.Decimal; 
                    values = new FacetValues { Precision = (byte?)null, Scale = (byte?)null };
                    break; 

                case DbType.Double:
                    primitiveTypeKind = PrimitiveTypeKind.Double;
                    break; 

                case DbType.Guid: 
                    primitiveTypeKind = PrimitiveTypeKind.Guid; 
                    break;
 
                case DbType.Int16:
                    primitiveTypeKind = PrimitiveTypeKind.Int16;
                    break;
 
                case DbType.Int32:
                    primitiveTypeKind = PrimitiveTypeKind.Int32; 
                    break; 

                case DbType.Int64: 
                    primitiveTypeKind = PrimitiveTypeKind.Int64;
                    break;

                case DbType.Single: 
                    primitiveTypeKind = PrimitiveTypeKind.Single;
                    break; 
 
                case DbType.SByte:
                    primitiveTypeKind = PrimitiveTypeKind.SByte; 
                    break;

                case DbType.VarNumeric:
                default: 
                    throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.EntityClient_UnsupportedDbType(dbType.ToString(), ParameterName));
            } 
 
            // If we get here, that means we got a type from the DbType, so get the mapped type
            PrimitiveType primitiveType = metadataWorkspace.GetModelPrimitiveType(primitiveTypeKind); 
            if (values == null)
            {
                values = new FacetValues();
            } 
            TypeUsage typeUsage = TypeUsage.Create(primitiveType, values);
 
            // If no suitable type was found, that means the basic type itself is valid, 
            // but one of the facets prevented us from finding a suitable store type
            if (null == typeUsage) 
            {
                throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.EntityClient_NoSuitableType(ParameterName));
            }
 
            return typeUsage;
        } 
 
        /// 
        /// Reset the dirty flag on the collection 
        /// 
        internal void ResetIsDirty()
        {
            _isDirty = false; 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner  [....], [....]
//--------------------------------------------------------------------- 
using System.Collections.Generic; 
using System.Text;
using System.Data; 
using System.Data.Common;
using System.Data.Common.CommandTrees;
using System.Data.Metadata.Edm;
using System.Text.RegularExpressions; 
using System.Diagnostics;
 
namespace System.Data.EntityClient 
{
    ///  
    /// Class representing a parameter used in EntityCommand
    /// 
    public sealed partial class EntityParameter : DbParameter, IDbDataParameter
    { 
        private string _parameterName;
        private DbType? _dbType; 
        private byte? _precision; 
        private byte? _scale;
        private bool _isDirty; 

        /// 
        /// Constructs the EntityParameter object
        ///  
        public EntityParameter()
        { 
        } 

        ///  
        /// Constructs the EntityParameter object with the given parameter name and the type of the parameter
        /// 
        /// The name of the parameter
        /// The type of the parameter 
        public EntityParameter(string parameterName, DbType dbType)
        { 
            SetParameterNameWithValidation(parameterName, "parameterName"); 
            this.DbType = dbType;
        } 

        /// 
        /// Constructs the EntityParameter object with the given parameter name, the type of the parameter, and the size of the
        /// parameter 
        /// 
        /// The name of the parameter 
        /// The type of the parameter 
        /// The size of the parameter
        public EntityParameter(string parameterName, DbType dbType, int size) 
        {
            SetParameterNameWithValidation(parameterName, "parameterName");
            this.DbType = dbType;
            this.Size = size; 
        }
 
        ///  
        /// Constructs the EntityParameter object with the given parameter name, the type of the parameter, the size of the
        /// parameter, and the name of the source column 
        /// 
        /// The name of the parameter
        /// The type of the parameter
        /// The size of the parameter 
        /// The name of the source column mapped to the data set, used for loading the parameter value
        public EntityParameter(string parameterName, DbType dbType, int size, string sourceColumn) 
        { 
            SetParameterNameWithValidation(parameterName, "parameterName");
            this.DbType = dbType; 
            this.Size = size;
            this.SourceColumn = sourceColumn;
        }
 
        /// 
        /// Constructs the EntityParameter object with the given parameter name, the type of the parameter, the size of the 
        /// parameter, and the name of the source column 
        /// 
        /// The name of the parameter 
        /// The type of the parameter
        /// The size of the parameter
        /// The direction of the parameter, whether it's input/output/both/return value
        /// If the parameter is nullable 
        /// The floating point precision of the parameter, valid only if the parameter type is a floating point type
        /// The scale of the parameter, valid only if the parameter type is a floating point type 
        /// The name of the source column mapped to the data set, used for loading the parameter value 
        /// The data row version to use when loading the parameter value
        /// The value of the parameter 
        public EntityParameter(string parameterName,
                            DbType dbType,
                            int size,
                            ParameterDirection direction, 
                            bool isNullable,
                            byte precision, 
                            byte scale, 
                            string sourceColumn,
                            DataRowVersion sourceVersion, 
                            object value)
        {
            SetParameterNameWithValidation(parameterName, "parameterName");
            this.DbType = dbType; 
            this.Size = size;
            this.Direction = direction; 
            this.IsNullable = isNullable; 
            this.Precision = precision;
            this.Scale = scale; 
            this.SourceColumn = sourceColumn;
            this.SourceVersion = sourceVersion;
            this.Value = value;
        } 

        ///  
        /// The name of the parameter 
        /// 
        public override string ParameterName 
        {
            get
            {
                return this._parameterName ?? ""; 
            }
            set 
            { 
                SetParameterNameWithValidation(value, "value");
            } 
        }

        /// 
        /// Helper method to validate the parameter name; Ideally we'd only call this once, but 
        /// we have to put an argumentName on the Argument exception, and the property setter would
        /// need "value" which confuses folks when they call the constructor that takes the value 
        /// of the parameter.  c'est la vie. 
        /// 
        ///  
        /// 
        private void SetParameterNameWithValidation(string parameterName, string argumentName)
        {
            if (!string.IsNullOrEmpty(parameterName) && !DbCommandTree.IsValidParameterName(parameterName)) 
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.EntityClient_InvalidParameterName(parameterName), argumentName); 
            } 
            PropertyChanging();
            this._parameterName = parameterName; 
        }

        /// 
        /// The type of the parameter 
        /// 
        public override DbType DbType 
        { 
            get
            { 
                // If the user hasn't set the DbType, then we deduce it from the value, but we won't set it in the
                // member field as it's used to keep track of what the user set explicitly
                if (!this._dbType.HasValue)
                { 
                    // If we can't deduce the type as there are no values, just assume it's string type
                    if (_value == null) 
                        return DbType.String; 

                    try 
                    {
                        return TypeHelpers.ConvertClrTypeToDbType(_value.GetType());
                    }
                    catch (ArgumentException e) 
                    {
                        throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.EntityClient_CannotDeduceDbType, e); 
                    } 
                }
 
                return (DbType)this._dbType;
            }
            set
            { 
                PropertyChanging();
                this._dbType = value; 
            } 
        }
 
        /// 
        /// The precision of the parameter if the parameter is a floating point type
        /// 
        public byte Precision 
        {
            get 
            { 
                byte result = this._precision.HasValue ? this._precision.Value : (byte)0;
                return result; 
            }
            set
            {
                PropertyChanging(); 
                this._precision = value;
            } 
        } 

        ///  
        /// The scale of the parameter if the parameter is a floating point type
        /// 
        public byte Scale
        { 
            get
            { 
                byte result = this._scale.HasValue ? this._scale.Value : (byte)0; 
                return result;
            } 
            set
            {
                PropertyChanging();
                this._scale = value; 
            }
        } 
 
        /// 
        /// The value of the parameter 
        /// 
        public override object Value
        {
            get 
            {
                return this._value; 
            } 
            set
            { 
                // If the user hasn't set the DbType, then we have to figure out if the DbType will change as a result
                // of the change in the value.  What we want to achieve is that changes to the value will not cause
                // it to be dirty, but changes to the value that causes the apparent DbType to change, then should be
                // dirty. 
                if (!this._dbType.HasValue)
                { 
                    // If the value is null, then we assume it's string type 
                    DbType oldDbType = DbType.String;
                    if (_value != null) 
                    {
                        oldDbType = TypeHelpers.ConvertClrTypeToDbType(_value.GetType());
                    }
 
                    // If the value is null, then we assume it's string type
                    DbType newDbType = DbType.String; 
                    if (value != null) 
                    {
                        newDbType = TypeHelpers.ConvertClrTypeToDbType(value.GetType()); 
                    }

                    if (oldDbType != newDbType)
                    { 
                        PropertyChanging();
                    } 
                } 

                this._value = value; 
            }
        }

        ///  
        /// Gets whether this collection has been changes since the last reset
        ///  
        internal bool IsDirty 
        {
            get 
            {
                return _isDirty;
            }
        } 

        ///  
        /// Indicates whether the DbType property has been set by the user; 
        /// 
        internal bool IsDbTypeSpecified 
        {
            get
            {
                return this._dbType.HasValue; 
            }
        } 
 
        /// 
        /// Indicates whether the Direction property has been set by the user; 
        /// 
        internal bool IsDirectionSpecified
        {
            get 
            {
                return this._direction != 0; 
            } 
        }
 
        /// 
        /// Indicates whether the IsNullable property has been set by the user;
        /// 
        internal bool IsIsNullableSpecified 
        {
            get 
            { 
                return this._isNullable.HasValue;
            } 
        }

        /// 
        /// Indicates whether the Precision property has been set by the user; 
        /// 
        internal bool IsPrecisionSpecified 
        { 
            get
            { 
                return this._precision.HasValue;
            }
        }
 
        /// 
        /// Indicates whether the Scale property has been set by the user; 
        ///  
        internal bool IsScaleSpecified
        { 
            get
            {
                return this._scale.HasValue;
            } 
        }
 
        ///  
        /// Indicates whether the Size property has been set by the user;
        ///  
        internal bool IsSizeSpecified
        {
            get
            { 
                return this._size.HasValue;
            } 
        } 

        ///  
        /// Resets the DbType property to its original settings
        /// 
        public override void ResetDbType()
        { 
            if (_dbType != null)
            { 
                PropertyChanging(); 
            }
 
            _dbType = null;
        }

        ///  
        /// Clones this parameter object
        ///  
        /// The new cloned object 
        internal EntityParameter Clone()
        { 
            return new EntityParameter(this);
        }

        ///  
        /// Clones this parameter object
        ///  
        /// The new cloned object 
        private void CloneHelper(EntityParameter destination)
        { 
            CloneHelperCore(destination);

            destination._parameterName = _parameterName;
            destination._dbType = _dbType; 
            destination._precision = _precision;
            destination._scale = _scale; 
        } 

        ///  
        /// Marks that this parameter has been changed
        /// 
        private void PropertyChanging()
        { 
            _isDirty = true;
        } 
 
        /// 
        /// Determines the size of the given object 
        /// 
        /// 
        /// 
        private int ValueSize(object value) 
        {
            return ValueSizeCore(value); 
        } 

        ///  
        /// Get the type usage for this parameter
        /// 
        /// The metadata workspace to where the type metadata is retrieved
        /// The type usage for this parameter 
        //NOTE: Because GetTypeUsage throws CommandValidationExceptions, it should only be called from EntityCommand during command execution
        internal TypeUsage GetTypeUsage(MetadataWorkspace metadataWorkspace) 
        { 
            FacetValues values = null;
 
            DbType dbType = this.DbType;
            PrimitiveTypeKind primitiveTypeKind = PrimitiveTypeKind.String;
            switch (dbType)
            { 
                case DbType.AnsiString:
                    values = new FacetValues { Unicode = false, FixedLength = false, MaxLength = (int?)null }; 
                    primitiveTypeKind = PrimitiveTypeKind.String; 
                    break;
 
                case DbType.AnsiStringFixedLength:
                    values = new FacetValues { Unicode = false, FixedLength = true, MaxLength = (int?)null };
                    primitiveTypeKind = PrimitiveTypeKind.String;
                    break; 

                case DbType.String: 
                    values = new FacetValues { Unicode = true, FixedLength = false, MaxLength = (int?)null }; 
                    primitiveTypeKind = PrimitiveTypeKind.String;
                    break; 

                case DbType.StringFixedLength:
                    values = new FacetValues { Unicode = true, FixedLength = true, MaxLength = (int?)null };
                    primitiveTypeKind = PrimitiveTypeKind.String; 
                    break;
 
                case DbType.Xml: 
                    // SQLBUDT #514204 - EntityCommand: XML parameter size must be ignored
                    /* XML parameters must not have a explicit size */ 
                    values = new FacetValues { Unicode = true, FixedLength = false, MaxLength = (int?)null };
                    primitiveTypeKind = PrimitiveTypeKind.String;
                    break;
 
                case DbType.Binary:
                    values = new FacetValues { MaxLength = (int?)null }; 
                    primitiveTypeKind = PrimitiveTypeKind.Binary; 
                    break;
 
                case DbType.Boolean:
                    primitiveTypeKind = PrimitiveTypeKind.Boolean;
                    break;
 
                case DbType.Byte:
                    primitiveTypeKind = PrimitiveTypeKind.Byte; 
                    break; 

                case DbType.DateTime: 
                case DbType.Date:
                    primitiveTypeKind = PrimitiveTypeKind.DateTime;
                    break;
 
                case DbType.DateTime2:
                    primitiveTypeKind = PrimitiveTypeKind.DateTime; 
                    values = new FacetValues { Precision = (byte?)null }; 
                    break;
 
                case DbType.Time:
                    primitiveTypeKind = PrimitiveTypeKind.Time;
                    values = new FacetValues { Precision = (byte?)null };
                    break; 

                case DbType.DateTimeOffset: 
                    primitiveTypeKind = PrimitiveTypeKind.DateTimeOffset; 
                    values = new FacetValues { Precision = (byte?)null };
                    break; 

                // For decimal and money, in the case of precision == 0, we don't want any facets when picking the type so the
                // default type should be picked
                case DbType.Decimal: 
                // SQLBU 480928: Need to make currency a separate case once we enable money type
                case DbType.Currency: 
                    primitiveTypeKind = PrimitiveTypeKind.Decimal; 
                    values = new FacetValues { Precision = (byte?)null, Scale = (byte?)null };
                    break; 

                case DbType.Double:
                    primitiveTypeKind = PrimitiveTypeKind.Double;
                    break; 

                case DbType.Guid: 
                    primitiveTypeKind = PrimitiveTypeKind.Guid; 
                    break;
 
                case DbType.Int16:
                    primitiveTypeKind = PrimitiveTypeKind.Int16;
                    break;
 
                case DbType.Int32:
                    primitiveTypeKind = PrimitiveTypeKind.Int32; 
                    break; 

                case DbType.Int64: 
                    primitiveTypeKind = PrimitiveTypeKind.Int64;
                    break;

                case DbType.Single: 
                    primitiveTypeKind = PrimitiveTypeKind.Single;
                    break; 
 
                case DbType.SByte:
                    primitiveTypeKind = PrimitiveTypeKind.SByte; 
                    break;

                case DbType.VarNumeric:
                default: 
                    throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.EntityClient_UnsupportedDbType(dbType.ToString(), ParameterName));
            } 
 
            // If we get here, that means we got a type from the DbType, so get the mapped type
            PrimitiveType primitiveType = metadataWorkspace.GetModelPrimitiveType(primitiveTypeKind); 
            if (values == null)
            {
                values = new FacetValues();
            } 
            TypeUsage typeUsage = TypeUsage.Create(primitiveType, values);
 
            // If no suitable type was found, that means the basic type itself is valid, 
            // but one of the facets prevented us from finding a suitable store type
            if (null == typeUsage) 
            {
                throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.EntityClient_NoSuitableType(ParameterName));
            }
 
            return typeUsage;
        } 
 
        /// 
        /// Reset the dirty flag on the collection 
        /// 
        internal void ResetIsDirty()
        {
            _isDirty = false; 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK