1 //---------------------------------------------------------------------
2 // <copyright file="EntitySetBase.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
11 using System.Collections.Generic;
12 using System.Data.Common;
13 using System.Diagnostics;
16 namespace System.Data.Metadata.Edm
19 /// Class for representing a entity set
21 public abstract class EntitySetBase : MetadataItem
23 //----------------------------------------------------------------------------------------------
24 // Possible Future Enhancement: revisit factoring of EntitySetBase and delta between C constructs and S constructs
26 // Currently, we need to have a way to map an entityset or a relationship set in S space
27 // to the appropriate structures in the store. In order to address this we said we would
28 // add new ItemAttributes (tableName, schemaName and catalogName to the EntitySetBase)...
29 // problem with this is that we are bleading a leaf-level, store specific set of constructs
30 // into the object model for things that may exist at either C or S.
32 // We need to do this for now to push forward on enabling the conversion but we need to re-examine
33 // whether we should have separate C and S space constructs or some other mechanism for
34 // maintaining this metadata.
35 //----------------------------------------------------------------------------------------------
39 /// The constructor for constructing the EntitySet with a given name and an entity type
41 /// <param name="name">The name of the EntitySet</param>
42 /// <param name="schema">The db schema</param>
43 /// <param name="table">The db table</param>
44 /// <param name="definingQuery">The provider specific query that should be used to retrieve the EntitySet</param>
45 /// <param name="entityType">The entity type of the entities that this entity set type contains</param>
46 /// <exception cref="System.ArgumentNullException">Thrown if the name or entityType argument is null</exception>
47 internal EntitySetBase(string name, string schema, string table, string definingQuery, EntityTypeBase entityType)
49 EntityUtil.GenericCheckArgumentNull(entityType, "entityType");
50 EntityUtil.CheckStringArgument(name, "name");
51 // SQLBU 480236: catalogName, schemaName & tableName are allowed to be null, empty & non-empty
55 //---- name of the 'schema'
56 //---- this is used by the SQL Gen utility to support generation of the correct name in the store
59 //---- name of the 'table'
60 //---- this is used by the SQL Gen utility to support generation of the correct name in the store
63 //---- the Provider specific query to use to retrieve the EntitySet data
64 _definingQuery = definingQuery;
66 this.ElementType = entityType;
71 private EntityContainer _entityContainer;
73 private EntityTypeBase _elementType;
74 private string _table;
75 private string _schema;
76 private string _definingQuery;
77 private string _cachedProviderSql;
83 /// Returns the kind of the type
85 public override BuiltInTypeKind BuiltInTypeKind { get { return BuiltInTypeKind.EntitySetBase; } }
89 /// Gets the identity for this item as a string
91 internal override string Identity
100 /// Gets or sets escaped SQL describing this entity set.
102 [MetadataProperty(PrimitiveTypeKind.String, false)]
103 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] // referenced by System.Data.Entity.Design.dll
104 internal string DefiningQuery
106 get { return _definingQuery; }
107 set { _definingQuery = value; }
111 /// Get and set by the provider only as a convientent place to
112 /// store the created sql fragment that represetnts this entity set
114 internal string CachedProviderSql
116 get { return _cachedProviderSql; }
117 set { _cachedProviderSql = value; }
121 /// Gets/Sets the name of this entity set
123 /// <exception cref="System.ArgumentNullException">Thrown if value passed into setter is null</exception>
124 /// <exception cref="System.InvalidOperationException">Thrown if the setter is called when EntitySetBase instance is in ReadOnly state</exception>
125 [MetadataProperty(PrimitiveTypeKind.String, false)]
135 /// Returns the entity container of the entity set
137 /// <exception cref="System.ArgumentNullException">Thrown if value passed into setter is null</exception>
138 /// <exception cref="System.InvalidOperationException">Thrown if the setter is called when the EntitySetBase instance or the EntityContainer passed into the setter is in ReadOnly state</exception>
139 public EntityContainer EntityContainer
143 return _entityContainer;
148 /// Gets/Sets the entity type of this entity set
150 /// <exception cref="System.ArgumentNullException">if value passed into setter is null</exception>
151 /// <exception cref="System.InvalidOperationException">Thrown if the setter is called when EntitySetBase instance is in ReadOnly state</exception>
152 [MetadataProperty(BuiltInTypeKind.EntityTypeBase, false)]
153 public EntityTypeBase ElementType
161 EntityUtil.GenericCheckArgumentNull(value, "value");
162 Util.ThrowIfReadOnly(this);
163 _elementType = value;
167 [MetadataProperty(PrimitiveTypeKind.String, false)]
168 internal string Table
176 [MetadataProperty(PrimitiveTypeKind.String, false)]
177 internal string Schema
188 /// Overriding System.Object.ToString to provide better String representation
191 public override string ToString()
197 /// Sets this item to be readonly, once this is set, the item will never be writable again.
199 internal override void SetReadOnly()
201 if (!this.IsReadOnly)
205 EntityTypeBase elementType = ElementType;
206 if (elementType != null)
208 elementType.SetReadOnly();
214 /// Change the entity container without doing fixup in the entity set collection
216 internal void ChangeEntityContainerWithoutCollectionFixup(EntityContainer newEntityContainer)
218 _entityContainer = newEntityContainer;