You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,289 @@
|
||||
//---------------------------------------------------------------------
|
||||
// <copyright file="DbParameterCollectionHelper.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.EntityClient
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public sealed partial class EntityParameterCollection : DbParameterCollection {
|
||||
private List<EntityParameter> _items;
|
||||
|
||||
override public int Count {
|
||||
get {
|
||||
|
||||
return ((null != _items) ? _items.Count : 0);
|
||||
}
|
||||
}
|
||||
|
||||
private List<EntityParameter> InnerList {
|
||||
get {
|
||||
List<EntityParameter> items = _items;
|
||||
|
||||
if (null == items) {
|
||||
items = new List<EntityParameter>();
|
||||
_items = items;
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
override public bool IsFixedSize {
|
||||
get {
|
||||
return ((System.Collections.IList)InnerList).IsFixedSize;
|
||||
}
|
||||
}
|
||||
|
||||
override public bool IsReadOnly {
|
||||
get {
|
||||
return ((System.Collections.IList)InnerList).IsReadOnly;
|
||||
}
|
||||
}
|
||||
|
||||
override public bool IsSynchronized {
|
||||
get {
|
||||
return ((System.Collections.ICollection)InnerList).IsSynchronized;
|
||||
}
|
||||
}
|
||||
|
||||
override public object SyncRoot {
|
||||
get {
|
||||
return ((System.Collections.ICollection)InnerList).SyncRoot;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
EditorBrowsableAttribute(EditorBrowsableState.Never)
|
||||
]
|
||||
override public int Add(object value) {
|
||||
OnChange();
|
||||
ValidateType(value);
|
||||
Validate(-1, value);
|
||||
InnerList.Add((EntityParameter)value);
|
||||
return Count-1;
|
||||
}
|
||||
|
||||
override public void AddRange(System.Array values) {
|
||||
OnChange();
|
||||
if (null == values) {
|
||||
throw EntityUtil.ArgumentNull("values");
|
||||
}
|
||||
foreach(object value in values) {
|
||||
ValidateType(value);
|
||||
}
|
||||
foreach(EntityParameter value in values) {
|
||||
Validate(-1, value);
|
||||
InnerList.Add((EntityParameter)value);
|
||||
}
|
||||
}
|
||||
|
||||
private int CheckName(string parameterName) {
|
||||
int index = IndexOf(parameterName);
|
||||
if (index < 0) {
|
||||
throw EntityUtil.EntityParameterCollectionInvalidParameterName(parameterName);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
override public void Clear() {
|
||||
OnChange();
|
||||
List<EntityParameter> items = InnerList;
|
||||
|
||||
if (null != items) {
|
||||
foreach(EntityParameter item in items) {
|
||||
item.ResetParent();
|
||||
}
|
||||
items.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
override public bool Contains(object value) {
|
||||
return (-1 != IndexOf(value));
|
||||
}
|
||||
|
||||
override public void CopyTo(Array array, int index) {
|
||||
((System.Collections.ICollection)InnerList).CopyTo(array, index);
|
||||
}
|
||||
|
||||
override public System.Collections.IEnumerator GetEnumerator() {
|
||||
return ((System.Collections.ICollection)InnerList).GetEnumerator();
|
||||
}
|
||||
|
||||
override protected DbParameter GetParameter(int index) {
|
||||
RangeCheck(index);
|
||||
return InnerList[index];
|
||||
}
|
||||
|
||||
override protected DbParameter GetParameter(string parameterName) {
|
||||
int index = IndexOf(parameterName);
|
||||
if (index < 0) {
|
||||
throw EntityUtil.EntityParameterCollectionInvalidParameterName(parameterName);
|
||||
}
|
||||
return InnerList[index];
|
||||
}
|
||||
|
||||
private static int IndexOf(System.Collections.IEnumerable items, string parameterName) {
|
||||
if (null != items) {
|
||||
int i = 0;
|
||||
|
||||
foreach(EntityParameter parameter in items) {
|
||||
if (0 == EntityUtil.SrcCompare(parameterName, parameter.ParameterName)) {
|
||||
return i;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
i = 0;
|
||||
|
||||
foreach(EntityParameter parameter in items) {
|
||||
if (0 == EntityUtil.DstCompare(parameterName, parameter.ParameterName)) {
|
||||
return i;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
override public int IndexOf(string parameterName) {
|
||||
return IndexOf(InnerList, parameterName);
|
||||
}
|
||||
|
||||
override public int IndexOf(object value) {
|
||||
if (null != value) {
|
||||
ValidateType(value);
|
||||
|
||||
List<EntityParameter> items = InnerList;
|
||||
|
||||
if (null != items) {
|
||||
int count = items.Count;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (value == items[i]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
override public void Insert(int index, object value) {
|
||||
OnChange();
|
||||
ValidateType(value);
|
||||
Validate(-1, (EntityParameter)value);
|
||||
InnerList.Insert(index, (EntityParameter)value);
|
||||
}
|
||||
|
||||
private void RangeCheck(int index) {
|
||||
if ((index < 0) || (Count <= index)) {
|
||||
throw EntityUtil.EntityParameterCollectionInvalidIndex(index, Count);
|
||||
}
|
||||
}
|
||||
|
||||
override public void Remove(object value) {
|
||||
OnChange();
|
||||
ValidateType(value);
|
||||
int index = IndexOf(value);
|
||||
if (-1 != index) {
|
||||
RemoveIndex(index);
|
||||
}
|
||||
else if (this != ((EntityParameter)value).CompareExchangeParent(null, this)) {
|
||||
throw EntityUtil.EntityParameterCollectionRemoveInvalidObject();
|
||||
}
|
||||
}
|
||||
|
||||
override public void RemoveAt(int index) {
|
||||
OnChange();
|
||||
RangeCheck(index);
|
||||
RemoveIndex(index);
|
||||
}
|
||||
|
||||
override public void RemoveAt(string parameterName) {
|
||||
OnChange();
|
||||
int index = CheckName(parameterName);
|
||||
RemoveIndex(index);
|
||||
}
|
||||
|
||||
private void RemoveIndex(int index) {
|
||||
List<EntityParameter> items = InnerList;
|
||||
Debug.Assert((null != items) && (0 <= index) && (index < Count), "RemoveIndex, invalid");
|
||||
EntityParameter item = items[index];
|
||||
items.RemoveAt(index);
|
||||
item.ResetParent();
|
||||
}
|
||||
|
||||
private void Replace(int index, object newValue) {
|
||||
List<EntityParameter> items = InnerList;
|
||||
Debug.Assert((null != items) && (0 <= index) && (index < Count), "Replace Index invalid");
|
||||
ValidateType(newValue);
|
||||
Validate(index, newValue);
|
||||
EntityParameter item = items[index];
|
||||
items[index] = (EntityParameter)newValue;
|
||||
item.ResetParent();
|
||||
}
|
||||
|
||||
override protected void SetParameter(int index, DbParameter value) {
|
||||
OnChange();
|
||||
RangeCheck(index);
|
||||
Replace(index, value);
|
||||
}
|
||||
|
||||
override protected void SetParameter(string parameterName, DbParameter value) {
|
||||
OnChange();
|
||||
int index = IndexOf(parameterName);
|
||||
if (index < 0) {
|
||||
throw EntityUtil.EntityParameterCollectionInvalidParameterName(parameterName);
|
||||
}
|
||||
Replace(index, value);
|
||||
}
|
||||
|
||||
private void Validate(int index, object value) {
|
||||
if (null == value) {
|
||||
throw EntityUtil.EntityParameterNull("value");
|
||||
}
|
||||
|
||||
object parent = ((EntityParameter)value).CompareExchangeParent(this, null);
|
||||
if (null != parent) {
|
||||
if (this != parent) {
|
||||
throw EntityUtil.EntityParameterContainedByAnotherCollection();
|
||||
}
|
||||
if (index != IndexOf(value)) {
|
||||
throw EntityUtil.EntityParameterContainedByAnotherCollection();
|
||||
}
|
||||
}
|
||||
|
||||
String name = ((EntityParameter)value).ParameterName;
|
||||
if (0 == name.Length) {
|
||||
index = 1;
|
||||
do {
|
||||
name = EntityUtil.Parameter + index.ToString(CultureInfo.CurrentCulture);
|
||||
index++;
|
||||
} while (-1 != IndexOf(name));
|
||||
((EntityParameter)value).ParameterName = name;
|
||||
}
|
||||
}
|
||||
|
||||
private void ValidateType(object value) {
|
||||
if (null == value) {
|
||||
throw EntityUtil.EntityParameterNull("value");
|
||||
}
|
||||
else if (!ItemType.IsInstanceOfType(value)) {
|
||||
throw EntityUtil.InvalidEntityParameterType(value);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
//---------------------------------------------------------------------
|
||||
// <copyright file="DbParameterHelper.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace System.Data.EntityClient {
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Entity;
|
||||
|
||||
public sealed partial class EntityParameter : DbParameter {
|
||||
private object _value;
|
||||
|
||||
private object _parent;
|
||||
|
||||
private ParameterDirection _direction;
|
||||
private int? _size;
|
||||
|
||||
|
||||
private string _sourceColumn;
|
||||
private DataRowVersion _sourceVersion;
|
||||
private bool _sourceColumnNullMapping;
|
||||
|
||||
private bool? _isNullable;
|
||||
|
||||
private object _coercedValue;
|
||||
|
||||
private EntityParameter(EntityParameter source) : this() {
|
||||
EntityUtil.CheckArgumentNull(source, "source");
|
||||
|
||||
source.CloneHelper(this);
|
||||
|
||||
ICloneable cloneable = (_value as ICloneable);
|
||||
if (null != cloneable) {
|
||||
_value = cloneable.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
private object CoercedValue {
|
||||
get {
|
||||
return _coercedValue;
|
||||
}
|
||||
set {
|
||||
_coercedValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
RefreshProperties(RefreshProperties.All),
|
||||
EntityResCategoryAttribute(EntityRes.DataCategory_Data),
|
||||
EntityResDescriptionAttribute(EntityRes.DbParameter_Direction),
|
||||
]
|
||||
override public ParameterDirection Direction {
|
||||
get {
|
||||
ParameterDirection direction = _direction;
|
||||
return ((0 != direction) ? direction : ParameterDirection.Input);
|
||||
}
|
||||
set {
|
||||
if (_direction != value) {
|
||||
switch (value) {
|
||||
case ParameterDirection.Input:
|
||||
case ParameterDirection.Output:
|
||||
case ParameterDirection.InputOutput:
|
||||
case ParameterDirection.ReturnValue:
|
||||
PropertyChanging();
|
||||
_direction = value;
|
||||
break;
|
||||
default:
|
||||
throw EntityUtil.InvalidParameterDirection(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public bool IsNullable {
|
||||
get {
|
||||
bool result = this._isNullable.HasValue ? this._isNullable.Value : true;
|
||||
return result;
|
||||
}
|
||||
set {
|
||||
_isNullable = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal int Offset {
|
||||
get {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
EntityResCategoryAttribute(EntityRes.DataCategory_Data),
|
||||
EntityResDescriptionAttribute(EntityRes.DbParameter_Size),
|
||||
]
|
||||
override public int Size {
|
||||
get {
|
||||
int size = _size.HasValue ? _size.Value : 0;
|
||||
if (0 == size) {
|
||||
size = ValueSize(Value);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
set {
|
||||
if (!_size.HasValue || _size.Value != value) {
|
||||
if (value < -1) {
|
||||
throw EntityUtil.InvalidSizeValue(value);
|
||||
}
|
||||
PropertyChanging();
|
||||
if (0 == value) {
|
||||
_size = null;
|
||||
}
|
||||
else {
|
||||
_size = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetSize() {
|
||||
if (_size.HasValue) {
|
||||
PropertyChanging();
|
||||
_size = null;
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldSerializeSize() {
|
||||
return (_size.HasValue && _size.Value != 0);
|
||||
}
|
||||
|
||||
[
|
||||
EntityResCategoryAttribute(EntityRes.DataCategory_Update),
|
||||
EntityResDescriptionAttribute(EntityRes.DbParameter_SourceColumn),
|
||||
]
|
||||
override public string SourceColumn {
|
||||
get {
|
||||
string sourceColumn = _sourceColumn;
|
||||
return ((null != sourceColumn) ? sourceColumn : string.Empty);
|
||||
}
|
||||
set {
|
||||
_sourceColumn = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool SourceColumnNullMapping {
|
||||
get {
|
||||
return _sourceColumnNullMapping;
|
||||
}
|
||||
set {
|
||||
_sourceColumnNullMapping = value;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
EntityResCategoryAttribute(EntityRes.DataCategory_Update),
|
||||
EntityResDescriptionAttribute(EntityRes.DbParameter_SourceVersion),
|
||||
]
|
||||
override public DataRowVersion SourceVersion {
|
||||
get {
|
||||
DataRowVersion sourceVersion = _sourceVersion;
|
||||
return ((0 != sourceVersion) ? sourceVersion : DataRowVersion.Current);
|
||||
}
|
||||
set {
|
||||
switch(value) {
|
||||
case DataRowVersion.Original:
|
||||
case DataRowVersion.Current:
|
||||
case DataRowVersion.Proposed:
|
||||
case DataRowVersion.Default:
|
||||
_sourceVersion = value;
|
||||
break;
|
||||
default:
|
||||
throw EntityUtil.InvalidDataRowVersion(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CloneHelperCore(EntityParameter destination) {
|
||||
destination._value = _value;
|
||||
|
||||
destination._direction = _direction;
|
||||
destination._size = _size;
|
||||
|
||||
destination._sourceColumn = _sourceColumn;
|
||||
destination._sourceVersion = _sourceVersion;
|
||||
destination._sourceColumnNullMapping = _sourceColumnNullMapping;
|
||||
destination._isNullable = _isNullable;
|
||||
}
|
||||
|
||||
internal void CopyTo(DbParameter destination) {
|
||||
EntityUtil.CheckArgumentNull(destination, "destination");
|
||||
CloneHelper((EntityParameter)destination);
|
||||
}
|
||||
|
||||
internal object CompareExchangeParent(object value, object comparand) {
|
||||
|
||||
|
||||
|
||||
|
||||
object parent = _parent;
|
||||
if (comparand == parent) {
|
||||
_parent = value;
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
internal void ResetParent() {
|
||||
_parent = null;
|
||||
}
|
||||
|
||||
override public string ToString() {
|
||||
return ParameterName;
|
||||
}
|
||||
|
||||
private byte ValuePrecisionCore(object value) {
|
||||
if (value is Decimal) {
|
||||
return ((System.Data.SqlTypes.SqlDecimal)(Decimal) value).Precision;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private byte ValueScaleCore(object value) {
|
||||
if (value is Decimal) {
|
||||
return (byte)((Decimal.GetBits((Decimal)value)[3] & 0x00ff0000) >> 0x10);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int ValueSizeCore(object value) {
|
||||
if (!EntityUtil.IsNull(value)) {
|
||||
string svalue = (value as string);
|
||||
if (null != svalue) {
|
||||
return svalue.Length;
|
||||
}
|
||||
byte[] bvalue = (value as byte[]);
|
||||
if (null != bvalue) {
|
||||
return bvalue.Length;
|
||||
}
|
||||
char[] cvalue = (value as char[]);
|
||||
if (null != cvalue) {
|
||||
return cvalue.Length;
|
||||
}
|
||||
if ((value is byte) || (value is char)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
//---------------------------------------------------------------------
|
||||
// <copyright file="EntityAdapter.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//---------------------------------------------------------------------
|
||||
namespace System.Data.EntityClient
|
||||
{
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.Mapping.Update.Internal;
|
||||
using System.Data.Objects;
|
||||
using System.Diagnostics;
|
||||
|
||||
/// <summary>
|
||||
/// Class representing a data adapter for the conceptual layer
|
||||
/// </summary>
|
||||
internal sealed class EntityAdapter : IEntityAdapter
|
||||
{
|
||||
private bool _acceptChangesDuringUpdate = true;
|
||||
private EntityConnection _connection;
|
||||
private Int32? _commandTimeout;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the EntityAdapter object without a connection object
|
||||
/// </summary>
|
||||
public EntityAdapter()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the map connection used by this adapter.
|
||||
/// </summary>
|
||||
DbConnection IEntityAdapter.Connection
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Connection;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.Connection = (EntityConnection)value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the map connection used by this adapter.
|
||||
/// </summary>
|
||||
public EntityConnection Connection
|
||||
{
|
||||
get
|
||||
{
|
||||
return _connection;
|
||||
}
|
||||
set
|
||||
{
|
||||
_connection = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the IEntityCache.AcceptChanges should be called during a call to IEntityAdapter.Update.
|
||||
/// </summary>
|
||||
public bool AcceptChangesDuringUpdate
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._acceptChangesDuringUpdate;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._acceptChangesDuringUpdate = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets of sets the command timeout for update operations. If null, indicates that the default timeout
|
||||
/// for the provider should be used.
|
||||
/// </summary>
|
||||
Int32? IEntityAdapter.CommandTimeout
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._commandTimeout;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._commandTimeout = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Persist modifications described in the given cache.
|
||||
/// </summary>
|
||||
/// <param name="entityCache">Entity cache containing changes to persist to the store.</param>
|
||||
/// <returns>Number of cache entries affected by the udpate.</returns>
|
||||
public Int32 Update(IEntityStateManager entityCache)
|
||||
{
|
||||
EntityUtil.CheckArgumentNull(entityCache, "entityCache");
|
||||
if (!IsStateManagerDirty(entityCache)) { return 0; }
|
||||
|
||||
// Check that we have a connection before we proceed
|
||||
if (_connection == null)
|
||||
{
|
||||
throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.EntityClient_NoConnectionForAdapter);
|
||||
}
|
||||
|
||||
// Check that the store connection is available
|
||||
if (_connection.StoreProviderFactory == null || this._connection.StoreConnection == null)
|
||||
{
|
||||
throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.EntityClient_NoStoreConnectionForUpdate);
|
||||
}
|
||||
|
||||
// Check that the connection is open before we proceed
|
||||
if (ConnectionState.Open != _connection.State)
|
||||
{
|
||||
throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.EntityClient_ClosedConnectionForUpdate);
|
||||
}
|
||||
|
||||
return UpdateTranslator.Update(entityCache, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine whether the cache has changes to apply.
|
||||
/// </summary>
|
||||
/// <param name="entityCache">ObjectStateManager to check. Must not be null.</param>
|
||||
/// <returns>true if cache contains changes entries; false otherwise</returns>
|
||||
private static bool IsStateManagerDirty(IEntityStateManager entityCache)
|
||||
{
|
||||
Debug.Assert(null != entityCache);
|
||||
bool hasChanges = false;
|
||||
// this call to GetCacheEntries is constant time (the ObjectStateManager implementation
|
||||
// maintains an explicit list of entries in each state)
|
||||
foreach (ObjectStateEntry entry in entityCache.GetEntityStateEntries(
|
||||
EntityState.Added | EntityState.Deleted | EntityState.Modified))
|
||||
{
|
||||
hasChanges = true;
|
||||
break;
|
||||
}
|
||||
return hasChanges;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,345 @@
|
||||
//---------------------------------------------------------------------
|
||||
// <copyright file="EntityConnectionStringBuilder.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.EntityClient
|
||||
{
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Data.Common;
|
||||
using System.Data.Entity;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
/// <summary>
|
||||
/// Class representing a connection string builder for the entity client provider
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "EntityConnectionStringBuilder follows the naming convention of DbConnectionStringBuilder.")]
|
||||
[SuppressMessage("Microsoft.Design", "CA1035:ICollectionImplementationsHaveStronglyTypedMembers", Justification = "There is no applicable strongly-typed implementation of CopyTo.")]
|
||||
public sealed class EntityConnectionStringBuilder : DbConnectionStringBuilder
|
||||
{
|
||||
// Names of parameters to look for in the connection string
|
||||
internal const string NameParameterName = "name";
|
||||
internal const string MetadataParameterName = "metadata";
|
||||
internal const string ProviderParameterName = "provider";
|
||||
internal const string ProviderConnectionStringParameterName = "provider connection string";
|
||||
|
||||
// An array to hold the keywords
|
||||
private static readonly string[] s_validKeywords = new string[]
|
||||
{
|
||||
NameParameterName,
|
||||
MetadataParameterName,
|
||||
ProviderParameterName,
|
||||
ProviderConnectionStringParameterName
|
||||
};
|
||||
|
||||
private static Hashtable s_synonyms;
|
||||
|
||||
// Information and data used by the connection
|
||||
private string _namedConnectionName;
|
||||
private string _providerName;
|
||||
private string _metadataLocations;
|
||||
private string _storeProviderConnectionString;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the EntityConnectionStringBuilder object
|
||||
/// </summary>
|
||||
public EntityConnectionStringBuilder()
|
||||
{
|
||||
// Everything just defaults to null
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the EntityConnectionStringBuilder object with a connection string
|
||||
/// </summary>
|
||||
/// <param name="connectionString">The connection string to initialize this builder</param>
|
||||
public EntityConnectionStringBuilder(string connectionString)
|
||||
{
|
||||
this.ConnectionString = connectionString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the named connection name in the connection string
|
||||
/// </summary>
|
||||
[DisplayName("Name")]
|
||||
[EntityResCategoryAttribute(EntityRes.EntityDataCategory_NamedConnectionString)]
|
||||
[EntityResDescriptionAttribute(EntityRes.EntityConnectionString_Name)]
|
||||
[RefreshProperties(RefreshProperties.All)]
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._namedConnectionName ?? "";
|
||||
}
|
||||
set
|
||||
{
|
||||
this._namedConnectionName = value;
|
||||
base[NameParameterName] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the underlying .NET Framework data provider in the connection string
|
||||
/// </summary>
|
||||
[DisplayName("Provider")]
|
||||
[EntityResCategoryAttribute(EntityRes.EntityDataCategory_Source)]
|
||||
[EntityResDescriptionAttribute(EntityRes.EntityConnectionString_Provider)]
|
||||
[RefreshProperties(RefreshProperties.All)]
|
||||
public string Provider
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._providerName ?? "";
|
||||
}
|
||||
set
|
||||
{
|
||||
this._providerName = value;
|
||||
base[ProviderParameterName] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the metadata locations in the connection string, which is a pipe-separated sequence
|
||||
/// of paths to folders and individual files
|
||||
/// </summary>
|
||||
[DisplayName("Metadata")]
|
||||
[EntityResCategoryAttribute(EntityRes.EntityDataCategory_Context)]
|
||||
[EntityResDescriptionAttribute(EntityRes.EntityConnectionString_Metadata)]
|
||||
[RefreshProperties(RefreshProperties.All)]
|
||||
public string Metadata
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._metadataLocations ?? "";
|
||||
}
|
||||
set
|
||||
{
|
||||
this._metadataLocations = value;
|
||||
base[MetadataParameterName] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the inner connection string in the connection string
|
||||
/// </summary>
|
||||
[DisplayName("Provider Connection String")]
|
||||
[EntityResCategoryAttribute(EntityRes.EntityDataCategory_Source)]
|
||||
[EntityResDescriptionAttribute(EntityRes.EntityConnectionString_ProviderConnectionString)]
|
||||
[RefreshProperties(RefreshProperties.All)]
|
||||
public string ProviderConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._storeProviderConnectionString ?? "";
|
||||
}
|
||||
set
|
||||
{
|
||||
this._storeProviderConnectionString = value;
|
||||
base[ProviderConnectionStringParameterName] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the EntityConnectionStringBuilder has a fixed size
|
||||
/// </summary>
|
||||
public override bool IsFixedSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of all keywords used by EntityConnectionStringBuilder
|
||||
/// </summary>
|
||||
public override ICollection Keys
|
||||
{
|
||||
get
|
||||
{
|
||||
return new System.Collections.ObjectModel.ReadOnlyCollection<string>(s_validKeywords);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a hash table object containing all the valid keywords. This is really the same as the Keys
|
||||
/// property, it's just that the returned object is a hash table.
|
||||
/// </summary>
|
||||
internal static Hashtable Synonyms
|
||||
{
|
||||
get
|
||||
{
|
||||
// Build the synonyms table if we don't have one
|
||||
if (s_synonyms == null)
|
||||
{
|
||||
Hashtable table = new Hashtable(s_validKeywords.Length);
|
||||
foreach (string keyword in s_validKeywords)
|
||||
{
|
||||
table.Add(keyword, keyword);
|
||||
}
|
||||
s_synonyms = table;
|
||||
}
|
||||
return s_synonyms;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value associated with the keyword
|
||||
/// </summary>
|
||||
public override object this[string keyword]
|
||||
{
|
||||
get
|
||||
{
|
||||
EntityUtil.CheckArgumentNull(keyword, "keyword");
|
||||
|
||||
// Just access the properties to get the value since the fields, which the properties will be accessing, will
|
||||
// have already been set when the connection string is set
|
||||
if (string.Compare(keyword, MetadataParameterName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
return this.Metadata;
|
||||
}
|
||||
else if (string.Compare(keyword, ProviderConnectionStringParameterName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
return this.ProviderConnectionString;
|
||||
}
|
||||
else if (string.Compare(keyword, NameParameterName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
return this.Name;
|
||||
}
|
||||
else if (string.Compare(keyword, ProviderParameterName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
return this.Provider;
|
||||
}
|
||||
|
||||
throw EntityUtil.KeywordNotSupported(keyword);
|
||||
}
|
||||
set
|
||||
{
|
||||
EntityUtil.CheckArgumentNull(keyword, "keyword");
|
||||
|
||||
// If a null value is set, just remove the parameter and return
|
||||
if (value == null)
|
||||
{
|
||||
this.Remove(keyword);
|
||||
return;
|
||||
}
|
||||
|
||||
// Since all of our parameters must be string value, perform the cast here and check
|
||||
string stringValue = value as string;
|
||||
if (stringValue == null)
|
||||
{
|
||||
throw EntityUtil.Argument(System.Data.Entity.Strings.EntityClient_ValueNotString, "value");
|
||||
}
|
||||
|
||||
// Just access the properties to get the value since the fields, which the properties will be accessing, will
|
||||
// have already been set when the connection string is set
|
||||
if (string.Compare(keyword, MetadataParameterName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
this.Metadata = stringValue;
|
||||
}
|
||||
else if (string.Compare(keyword, ProviderConnectionStringParameterName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
this.ProviderConnectionString = stringValue;
|
||||
}
|
||||
else if (string.Compare(keyword, NameParameterName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
this.Name = stringValue;
|
||||
}
|
||||
else if (string.Compare(keyword, ProviderParameterName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
this.Provider = stringValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw EntityUtil.KeywordNotSupported(keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear all the parameters in the connection string
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
this._namedConnectionName = null;
|
||||
this._providerName = null;
|
||||
this._metadataLocations = null;
|
||||
this._storeProviderConnectionString = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine if this connection string builder contains a specific key
|
||||
/// </summary>
|
||||
/// <param name="keyword">The keyword to find in this connection string builder</param>
|
||||
/// <returns>True if this connections string builder contains the specific key</returns>
|
||||
public override bool ContainsKey(string keyword)
|
||||
{
|
||||
EntityUtil.CheckArgumentNull(keyword, "keyword");
|
||||
|
||||
foreach (string validKeyword in s_validKeywords)
|
||||
{
|
||||
if (validKeyword.Equals(keyword, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the given keyword, returns false if there isn't a value with the given keyword
|
||||
/// </summary>
|
||||
/// <param name="keyword">The keyword specifying the name of the parameter to retrieve</param>
|
||||
/// <param name="value">The value retrieved</param>
|
||||
/// <returns>True if the value is retrieved</returns>
|
||||
public override bool TryGetValue(string keyword, out object value)
|
||||
{
|
||||
EntityUtil.CheckArgumentNull(keyword, "keyword");
|
||||
|
||||
if (ContainsKey(keyword))
|
||||
{
|
||||
value = this[keyword];
|
||||
return true;
|
||||
}
|
||||
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a parameter from the builder
|
||||
/// </summary>
|
||||
/// <param name="keyword">The keyword specifying the name of the parameter to remove</param>
|
||||
/// <returns>True if the parameter is removed</returns>
|
||||
public override bool Remove(string keyword)
|
||||
{
|
||||
EntityUtil.CheckArgumentNull(keyword, "keyword");
|
||||
|
||||
// Convert the given object into a string
|
||||
if (string.Compare(keyword, MetadataParameterName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
this._metadataLocations = null;
|
||||
}
|
||||
else if (string.Compare(keyword, ProviderConnectionStringParameterName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
this._storeProviderConnectionString = null;
|
||||
}
|
||||
else if (string.Compare(keyword, NameParameterName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
this._namedConnectionName = null;
|
||||
}
|
||||
else if (string.Compare(keyword, ProviderParameterName, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
this._providerName = null;
|
||||
}
|
||||
|
||||
return base.Remove(keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,221 @@
|
||||
//---------------------------------------------------------------------
|
||||
// <copyright file="EntityParameterCollection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//---------------------------------------------------------------------
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
//---------------------------------------------------------------------
|
||||
// <copyright file="EntityProviderFactory.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//---------------------------------------------------------------------
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
|
||||
namespace System.Data.EntityClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Class representing a provider factory for the entity client provider
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2302", Justification="We don't expect serviceType to be an Embedded Interop Types.")]
|
||||
public sealed class EntityProviderFactory : DbProviderFactory, IServiceProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// A singleton object for the entity client provider factory object
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "EntityProviderFactory implements the singleton pattern and it's stateless. This is needed in order to work with DbProviderFactories.")]
|
||||
public static readonly EntityProviderFactory Instance = new EntityProviderFactory();
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the EntityProviderFactory object, this is private as users shouldn't create it directly
|
||||
/// </summary>
|
||||
private EntityProviderFactory()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a EntityCommand object and returns it
|
||||
/// </summary>
|
||||
/// <returns>A EntityCommand object</returns>
|
||||
public override DbCommand CreateCommand()
|
||||
{
|
||||
return new EntityCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a EntityCommandBuilder object and returns it
|
||||
/// </summary>
|
||||
/// <returns>A EntityCommandBuilder object</returns>
|
||||
/// <exception cref="NotSupportedException"></exception>
|
||||
public override DbCommandBuilder CreateCommandBuilder()
|
||||
{
|
||||
throw EntityUtil.NotSupported();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a EntityConnection object and returns it
|
||||
/// </summary>
|
||||
/// <returns>A EntityConnection object</returns>
|
||||
public override DbConnection CreateConnection()
|
||||
{
|
||||
return new EntityConnection();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a EntityConnectionStringBuilder object and returns it
|
||||
/// </summary>
|
||||
/// <returns>A EntityConnectionStringBuilder object</returns>
|
||||
public override DbConnectionStringBuilder CreateConnectionStringBuilder()
|
||||
{
|
||||
return new EntityConnectionStringBuilder();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a DbDataAdapter object and returns it, this method is currently not supported
|
||||
/// </summary>
|
||||
/// <returns>A DbDataAdapter object</returns>
|
||||
/// <exception cref="NotSupportedException"></exception>
|
||||
public override DbDataAdapter CreateDataAdapter()
|
||||
{
|
||||
throw EntityUtil.NotSupported();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a EntityParameter object and returns it
|
||||
/// </summary>
|
||||
/// <returns>A EntityParameter object</returns>
|
||||
public override DbParameter CreateParameter()
|
||||
{
|
||||
return new EntityParameter();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a CodeAccessPermission object and returns it
|
||||
/// </summary>
|
||||
/// <param name="state">The permission state level for the code access</param>
|
||||
/// <returns>A CodeAccessPermission object</returns>
|
||||
public override CodeAccessPermission CreatePermission(PermissionState state)
|
||||
{
|
||||
throw EntityUtil.NotSupported();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extension mechanism for additional services;
|
||||
/// </summary>
|
||||
/// <returns>requested service provider or null.</returns>
|
||||
object IServiceProvider.GetService(Type serviceType) {
|
||||
object result = null;
|
||||
if (serviceType == typeof(DbProviderServices)) {
|
||||
result = EntityProviderServices.Instance;
|
||||
}
|
||||
else if (serviceType == typeof(IEntityAdapter)) {
|
||||
result = new EntityAdapter();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="EntityProviderServices.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.EntityClient {
|
||||
|
||||
using System.Data.Common;
|
||||
using System.Data.Common.CommandTrees;
|
||||
using System.Data.Entity;
|
||||
using System.Data.Metadata.Edm;
|
||||
using System.Diagnostics;
|
||||
|
||||
/// <summary>
|
||||
/// The class for provider services of the entity client
|
||||
/// </summary>
|
||||
internal sealed class EntityProviderServices : DbProviderServices {
|
||||
|
||||
/// <summary>
|
||||
/// Singleton object;
|
||||
/// </summary>
|
||||
internal static readonly EntityProviderServices Instance = new EntityProviderServices();
|
||||
|
||||
/// <summary>
|
||||
/// Create a Command Definition object, given the connection and command tree
|
||||
/// </summary>
|
||||
/// <param name="connection">connection to the underlying provider</param>
|
||||
/// <param name="commandTree">command tree for the statement</param>
|
||||
/// <returns>an exectable command definition object</returns>
|
||||
/// <exception cref="ArgumentNullException">connection and commandTree arguments must not be null</exception>
|
||||
protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree) {
|
||||
EntityUtil.CheckArgumentNull(providerManifest, "providerManifest");
|
||||
EntityUtil.CheckArgumentNull(commandTree, "commandTree");
|
||||
|
||||
StoreItemCollection storeMetadata = (StoreItemCollection)commandTree.MetadataWorkspace.GetItemCollection(DataSpace.SSpace);
|
||||
return this.CreateCommandDefinition(storeMetadata.StoreProviderFactory, commandTree);
|
||||
}
|
||||
|
||||
internal EntityCommandDefinition CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree) {
|
||||
EntityUtil.CheckArgumentNull(storeProviderFactory, "storeProviderFactory");
|
||||
Debug.Assert(commandTree != null, "Command Tree cannot be null");
|
||||
|
||||
return new EntityCommandDefinition(storeProviderFactory, commandTree);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the data space of the specified command tree is the model (C-) space
|
||||
/// </summary>
|
||||
/// <param name="commandTree">The command tree for which the data space should be validated</param>
|
||||
internal override void ValidateDataSpace(DbCommandTree commandTree)
|
||||
{
|
||||
Debug.Assert(commandTree != null, "Ensure command tree is non-null before calling ValidateDataSpace");
|
||||
|
||||
if (commandTree.DataSpace != DataSpace.CSpace)
|
||||
{
|
||||
throw EntityUtil.ProviderIncompatible(Strings.EntityClient_RequiresNonStoreCommandTree);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a EntityCommandDefinition object based on the prototype command
|
||||
/// This method is intended for provider writers to build a default command definition
|
||||
/// from a command.
|
||||
/// </summary>
|
||||
/// <param name="prototype"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException">prototype argument must not be null</exception>
|
||||
/// <exception cref="InvalidCastException">prototype argument must be a EntityCommand</exception>
|
||||
public override DbCommandDefinition CreateCommandDefinition(DbCommand prototype) {
|
||||
EntityUtil.CheckArgumentNull(prototype, "prototype");
|
||||
return ((EntityCommand)prototype).GetCommandDefinition();
|
||||
}
|
||||
|
||||
protected override string GetDbProviderManifestToken(DbConnection connection)
|
||||
{
|
||||
EntityUtil.CheckArgumentNull(connection, "connection");
|
||||
if (connection.GetType() != typeof(EntityConnection))
|
||||
{
|
||||
throw EntityUtil.Argument(System.Data.Entity.Strings.Mapping_Provider_WrongConnectionType(typeof(EntityConnection)));
|
||||
}
|
||||
|
||||
return MetadataItem.EdmProviderManifest.Token;
|
||||
}
|
||||
|
||||
protected override DbProviderManifest GetDbProviderManifest(string versionHint)
|
||||
{
|
||||
EntityUtil.CheckArgumentNull(versionHint, "versionHint");
|
||||
return MetadataItem.EdmProviderManifest;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
//---------------------------------------------------------------------
|
||||
// <copyright file="EntityTransaction.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//---------------------------------------------------------------------
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace System.Data.EntityClient
|
||||
{
|
||||
using Metadata.Edm;
|
||||
|
||||
/// <summary>
|
||||
/// Class representing a transaction for the conceptual layer
|
||||
/// </summary>
|
||||
public sealed class EntityTransaction : DbTransaction
|
||||
{
|
||||
private EntityConnection _connection;
|
||||
private DbTransaction _storeTransaction;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs the EntityTransaction object with an associated connection and the underlying store transaction
|
||||
/// </summary>
|
||||
/// <param name="connection">The EntityConnetion object owning this transaction</param>
|
||||
/// <param name="storeTransaction">The underlying transaction object</param>
|
||||
internal EntityTransaction(EntityConnection connection, DbTransaction storeTransaction)
|
||||
: base()
|
||||
{
|
||||
Debug.Assert(connection != null && storeTransaction != null);
|
||||
|
||||
this._connection = connection;
|
||||
this._storeTransaction = storeTransaction;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The connection object owning this transaction object
|
||||
/// </summary>
|
||||
public new EntityConnection Connection
|
||||
{
|
||||
get
|
||||
{ // follow the store transaction behavior
|
||||
return ((null != _storeTransaction.Connection) ? _connection : null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The connection object owning this transaction object
|
||||
/// </summary>
|
||||
protected override DbConnection DbConnection
|
||||
{
|
||||
get
|
||||
{ // follow the store transaction behavior
|
||||
return ((null != _storeTransaction.Connection) ? _connection : null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The isolation level of this transaction
|
||||
/// </summary>
|
||||
public override IsolationLevel IsolationLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._storeTransaction.IsolationLevel;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the DbTransaction for the underlying provider transaction
|
||||
/// </summary>
|
||||
internal DbTransaction StoreTransaction
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._storeTransaction;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Commits the transaction
|
||||
/// </summary>
|
||||
public override void Commit()
|
||||
{
|
||||
try
|
||||
{
|
||||
this._storeTransaction.Commit();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (EntityUtil.IsCatchableExceptionType(e))
|
||||
{
|
||||
throw EntityUtil.Provider(@"Commit", e);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
||||
this.ClearCurrentTransaction();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rolls back the transaction
|
||||
/// </summary>
|
||||
public override void Rollback()
|
||||
{
|
||||
try
|
||||
{
|
||||
this._storeTransaction.Rollback();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (EntityUtil.IsCatchableExceptionType(e))
|
||||
{
|
||||
throw EntityUtil.Provider(@"Rollback", e);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
||||
this.ClearCurrentTransaction();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleans up this transaction object
|
||||
/// </summary>
|
||||
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
this.ClearCurrentTransaction();
|
||||
this._storeTransaction.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to wrap EntityConnection.ClearCurrentTransaction()
|
||||
/// </summary>
|
||||
private void ClearCurrentTransaction()
|
||||
{
|
||||
if (_connection.CurrentTransaction == this)
|
||||
{
|
||||
_connection.ClearCurrentTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="NameValuePair.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Data.EntityClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Copied from System.Data.dll
|
||||
/// </summary>
|
||||
sealed internal class NameValuePair {
|
||||
readonly private string _name;
|
||||
readonly private string _value;
|
||||
readonly private int _length;
|
||||
private NameValuePair _next;
|
||||
|
||||
internal NameValuePair(string name, string value, int length) {
|
||||
System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(name), "empty keyname");
|
||||
_name = name;
|
||||
_value = value;
|
||||
_length = length;
|
||||
}
|
||||
|
||||
internal NameValuePair Next {
|
||||
get {
|
||||
return _next;
|
||||
}
|
||||
set {
|
||||
if ((null != _next) || (null == value)) {
|
||||
throw EntityUtil.InternalError(EntityUtil.InternalErrorCode.NameValuePairNext);
|
||||
}
|
||||
_next = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user