1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
//---------------------------------------------------------------------
// <copyright file="EntityParameterCollection.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.Metadata.Edm;
namespace System.Data.EntityClient
{
/// <summary>
/// Class representing a parameter collection used in EntityCommand
/// </summary>
public sealed partial class EntityParameterCollection : DbParameterCollection
{
private static Type ItemType = typeof(EntityParameter);
private bool _isDirty;
/// <summary>
/// Constructs the EntityParameterCollection object
/// </summary>
internal EntityParameterCollection()
: base()
{
}
/// <summary>
/// Gets the parameter from the collection at the specified index
/// </summary>
/// <param name="index">The index of the parameter to retrieved</param>
/// <returns>The parameter at the index</returns>
public new EntityParameter this[int index]
{
get
{
return (EntityParameter)this.GetParameter(index);
}
set
{
this.SetParameter(index, value);
}
}
/// <summary>
/// Gets the parameter with the given name from the collection
/// </summary>
/// <param name="parameterName">The name of the parameter to retrieved</param>
/// <returns>The parameter with the given name</returns>
public new EntityParameter this[string parameterName]
{
get
{
return (EntityParameter)this.GetParameter(parameterName);
}
set
{
this.SetParameter(parameterName, value);
}
}
/// <summary>
/// Gets whether this collection has been changes since the last reset
/// </summary>
internal bool IsDirty
{
get
{
if (_isDirty)
{
return true;
}
// Loop through and return true if any parameter is dirty
foreach (EntityParameter parameter in this)
{
if (parameter.IsDirty)
{
return true;
}
}
return false;
}
}
/// <summary>
/// Add a EntityParameter to the collection
/// </summary>
/// <param name="value">The parameter to add to the collection</param>
/// <returns>The index of the new parameter within the collection</returns>
public EntityParameter Add(EntityParameter value)
{
this.Add((object)value);
return value;
}
/// <summary>
/// Add a EntityParameter with the given name and value to the collection
/// </summary>
/// <param name="parameterName">The name of the parameter to add</param>
/// <param name="value">The value of the parameter to add</param>
/// <returns>The index of the new parameter within the collection</returns>
public EntityParameter AddWithValue(string parameterName, object value)
{
EntityParameter param = new EntityParameter();
param.ParameterName = parameterName;
param.Value = value;
return this.Add(param);
}
/// <summary>
/// Adds a EntityParameter with the given name and type to the collection
/// </summary>
/// <param name="parameterName">The name of the parameter to add</param>
/// <param name="dbType">The type of the parameter</param>
/// <returns>The index of the new parameter within the collection</returns>
public EntityParameter Add(string parameterName, DbType dbType)
{
return this.Add(new EntityParameter(parameterName, dbType));
}
/// <summary>
/// Add a EntityParameter with the given name, type, and size to the collection
/// </summary>
/// <param name="parameterName">The name of the parameter to add</param>
/// <param name="dbType">The type of the parameter</param>
/// <param name="size">The size of the parameter</param>
/// <returns>The index of the new parameter within the collection</returns>
public EntityParameter Add(string parameterName, DbType dbType, int size)
{
return this.Add(new EntityParameter(parameterName, dbType, size));
}
/// <summary>
/// Adds a range of EntityParameter objects to this collection
/// </summary>
/// <param name="values">The arary of EntityParameter objects to add</param>
public void AddRange(EntityParameter[] values)
{
this.AddRange((Array)values);
}
/// <summary>
/// Check if the collection has a parameter with the given parameter name
/// </summary>
/// <param name="parameterName">The parameter name to look for</param>
/// <returns>True if the collection has a parameter with the given name</returns>
public override bool Contains(string parameterName)
{
return this.IndexOf(parameterName) != -1;
}
/// <summary>
/// Copies the given array of parameters into this collection
/// </summary>
/// <param name="array">The array to copy into</param>
/// <param name="index">The index in the array where the copy starts</param>
public void CopyTo(EntityParameter[] array, int index)
{
this.CopyTo((Array)array, index);
}
/// <summary>
/// Finds the index in the collection of the given parameter object
/// </summary>
/// <param name="value">The parameter to search for</param>
/// <returns>The index of the parameter, -1 if not found</returns>
public int IndexOf(EntityParameter value)
{
return IndexOf((object)value);
}
/// <summary>
/// Add a EntityParameter with the given value to the collection at a location indicated by the index
/// </summary>
/// <param name="index">The index at which the parameter is to be inserted</param>
/// <param name="value">The value of the parameter</param>
public void Insert(int index, EntityParameter value)
{
this.Insert(index, (object)value);
}
/// <summary>
/// Marks that this collection has been changed
/// </summary>
private void OnChange()
{
_isDirty = true;
}
/// <summary>
/// Remove a EntityParameter with the given value from the collection
/// </summary>
/// <param name="value">The parameter to remove</param>
public void Remove(EntityParameter value)
{
this.Remove((object)value);
}
/// <summary>
/// Reset the dirty flag on the collection
/// </summary>
internal void ResetIsDirty()
{
_isDirty = false;
// Loop through and reset each parameter
foreach (EntityParameter parameter in this)
{
parameter.ResetIsDirty();
}
}
}
}
|