1 //---------------------------------------------------------------------
2 // <copyright file="EntityProviderFactory.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
8 //---------------------------------------------------------------------
9 using System.Collections.Generic;
10 using System.Diagnostics.CodeAnalysis;
13 using System.Data.Common;
14 using System.Security;
15 using System.Security.Permissions;
17 namespace System.Data.EntityClient
20 /// Class representing a provider factory for the entity client provider
22 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2302", Justification="We don't expect serviceType to be an Embedded Interop Types.")]
23 public sealed class EntityProviderFactory : DbProviderFactory, IServiceProvider
26 /// A singleton object for the entity client provider factory object
28 [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "EntityProviderFactory implements the singleton pattern and it's stateless. This is needed in order to work with DbProviderFactories.")]
29 public static readonly EntityProviderFactory Instance = new EntityProviderFactory();
32 /// Constructs the EntityProviderFactory object, this is private as users shouldn't create it directly
34 private EntityProviderFactory()
39 /// Creates a EntityCommand object and returns it
41 /// <returns>A EntityCommand object</returns>
42 public override DbCommand CreateCommand()
44 return new EntityCommand();
48 /// Creates a EntityCommandBuilder object and returns it
50 /// <returns>A EntityCommandBuilder object</returns>
51 /// <exception cref="NotSupportedException"></exception>
52 public override DbCommandBuilder CreateCommandBuilder()
54 throw EntityUtil.NotSupported();
58 /// Creates a EntityConnection object and returns it
60 /// <returns>A EntityConnection object</returns>
61 public override DbConnection CreateConnection()
63 return new EntityConnection();
67 /// Creates a EntityConnectionStringBuilder object and returns it
69 /// <returns>A EntityConnectionStringBuilder object</returns>
70 public override DbConnectionStringBuilder CreateConnectionStringBuilder()
72 return new EntityConnectionStringBuilder();
76 /// Creates a DbDataAdapter object and returns it, this method is currently not supported
78 /// <returns>A DbDataAdapter object</returns>
79 /// <exception cref="NotSupportedException"></exception>
80 public override DbDataAdapter CreateDataAdapter()
82 throw EntityUtil.NotSupported();
86 /// Creates a EntityParameter object and returns it
88 /// <returns>A EntityParameter object</returns>
89 public override DbParameter CreateParameter()
91 return new EntityParameter();
95 /// Creates a CodeAccessPermission object and returns it
97 /// <param name="state">The permission state level for the code access</param>
98 /// <returns>A CodeAccessPermission object</returns>
99 public override CodeAccessPermission CreatePermission(PermissionState state)
101 throw EntityUtil.NotSupported();
105 /// Extension mechanism for additional services;
107 /// <returns>requested service provider or null.</returns>
108 object IServiceProvider.GetService(Type serviceType) {
109 object result = null;
110 if (serviceType == typeof(DbProviderServices)) {
111 result = EntityProviderServices.Instance;
113 else if (serviceType == typeof(IEntityAdapter)) {
114 result = new EntityAdapter();