internal StorageModificationFunctionMapping( EntitySetBase entitySet, EntityTypeBase entityType, EdmFunction function, IEnumerable<StorageModificationFunctionParameterBinding> parameterBindings, FunctionParameter rowsAffectedParameter, IEnumerable<StorageModificationFunctionResultBinding> resultBindings) { Contract.Requires(entitySet != null); Contract.Requires(function != null); Contract.Requires(parameterBindings != null); Function = function; RowsAffectedParameter = rowsAffectedParameter; ParameterBindings = parameterBindings.ToList().AsReadOnly(); if (null != resultBindings) { var bindings = resultBindings.ToList(); if (0 < bindings.Count) { ResultBindings = bindings.AsReadOnly(); } } CollocatedAssociationSetEnds = GetReferencedAssociationSetEnds(entitySet as EntitySet, entityType as EntityType, parameterBindings) .ToList() .AsReadOnly(); }
internal StorageModificationFunctionMapping( EntitySetBase entitySet, EntityTypeBase entityType, EdmFunction function, IEnumerable<StorageModificationFunctionParameterBinding> parameterBindings, FunctionParameter rowsAffectedParameter, IEnumerable<StorageModificationFunctionResultBinding> resultBindings) { DebugCheck.NotNull(entitySet); DebugCheck.NotNull(function); DebugCheck.NotNull(parameterBindings); _function = function; _rowsAffectedParameter = rowsAffectedParameter; ParameterBindings = parameterBindings.ToList().AsReadOnly(); if (null != resultBindings) { var bindings = resultBindings.ToList(); if (0 < bindings.Count) { ResultBindings = bindings.AsReadOnly(); } } CollocatedAssociationSetEnds = GetReferencedAssociationSetEnds(entitySet as EntitySet, entityType as EntityType, parameterBindings) .ToList() .AsReadOnly(); }
/// <summary> /// Gets a view corresponding to the specified extent. /// </summary> /// <param name="extent">The extent.</param> /// <returns>The mapping view, or null if the extent is not associated with a mapping view.</returns> public override DbMappingView GetView(EntitySetBase extent) { if (extent == null) { throw new ArgumentNullException("extent"); } var extentName = extent.EntityContainer.Name + "." + extent.Name; if (extentName == "docXModelStoreContainer.UserDetails") { return GetView0(); } if (extentName == "docXEntities.UserDetails") { return GetView1(); } if (extentName == "docXModelStoreContainer.Users") { return GetView2(); } if (extentName == "docXEntities.Users") { return GetView3(); } return null; }
/// <summary> /// Gets a view corresponding to the specified extent. /// </summary> /// <param name="extent">The extent.</param> /// <returns>The mapping view, or null if the extent is not associated with a mapping view.</returns> public override DbMappingView GetView(EntitySetBase extent) { if (extent == null) { throw new ArgumentNullException("extent"); } var extentName = extent.EntityContainer.Name + "." + extent.Name; if (extentName == "CodeFirstDatabase.Company") { return GetView0(); } if (extentName == "CodeFirstDatabase.CompanyProduct") { return GetView1(); } if (extentName == "CompanyContext.Company") { return GetView2(); } if (extentName == "CompanyContext.CompanyProduct") { return GetView3(); } return null; }
/// <summary> /// Initializes a new ModificationFunctionMapping instance. /// </summary> /// <param name="entitySet">The entity or association set.</param> /// <param name="entityType">The entity or association type.</param> /// <param name="function">The metadata of function to which we should bind.</param> /// <param name="parameterBindings">Bindings for function parameters.</param> /// <param name="rowsAffectedParameter">The output parameter producing number of rows affected.</param> /// <param name="resultBindings">Bindings for the results of function evaluation</param> public ModificationFunctionMapping( EntitySetBase entitySet, EntityTypeBase entityType, EdmFunction function, IEnumerable<ModificationFunctionParameterBinding> parameterBindings, FunctionParameter rowsAffectedParameter, IEnumerable<ModificationFunctionResultBinding> resultBindings) { Check.NotNull(entitySet, "entitySet"); Check.NotNull(function, "function"); Check.NotNull(parameterBindings, "parameterBindings"); _function = function; _rowsAffectedParameter = rowsAffectedParameter; _parameterBindings = new ReadOnlyCollection<ModificationFunctionParameterBinding>(parameterBindings.ToList()); if (null != resultBindings) { var bindings = resultBindings.ToList(); if (0 < bindings.Count) { _resultBindings = new ReadOnlyCollection<ModificationFunctionResultBinding>(bindings); } } _collocatedAssociationSetEnds = new ReadOnlyCollection<AssociationSetEnd>( GetReferencedAssociationSetEnds(entitySet as EntitySet, entityType as EntityType, parameterBindings) .ToList()); }
/// <summary> /// Creates a "flattened" table definition. /// /// The table has one column for each specified property in the "properties" parameter. /// The name and datatype of each table column are taken from the corresponding property. /// /// The keys of the table (if any) are those specified in the "keyProperties" parameter /// /// The table may correspond to an entity set (if the entityset parameter was non-null) /// </summary> /// <param name="properties">prperties corresponding to columns of the table</param> /// <param name="keyProperties"></param> /// <param name="extent">entityset corresponding to the table (if any)</param> internal TableMD( IEnumerable<EdmProperty> properties, IEnumerable<EdmMember> keyProperties, EntitySetBase extent) : this(extent) { var columnMap = new Dictionary<string, ColumnMD>(); m_flattened = true; foreach (var p in properties) { var newColumn = new ColumnMD(p); m_columns.Add(newColumn); columnMap[p.Name] = newColumn; } foreach (var p in keyProperties) { ColumnMD keyColumn; if (!columnMap.TryGetValue(p.Name, out keyColumn)) { Debug.Assert(false, "keyMember not in columns?"); } else { m_keys.Add(keyColumn); } } }
public override DbMappingView GetView(EntitySetBase extent) { var extentFullName = extent.EntityContainer.Name + "." + extent.Name; switch (extentFullName) { case "CodeFirstDatabase.PregenBlog": View0Accessed = true; return new DbMappingView( @"SELECT VALUE -- Constructing PregenBlog [CodeFirstDatabaseSchema.PregenBlog](T1.PregenBlog_Id) FROM ( SELECT T.Id AS PregenBlog_Id, True AS _from0 FROM CodeFirstContainer.PregenBlogs AS T ) AS T1"); case "CodeFirstContainer.PregenBlogs": View1Accessed = true; return new DbMappingView( @"SELECT VALUE -- Constructing PregenBlogs [CodeFirstNamespace.PregenBlog](T1.PregenBlog_Id) FROM ( SELECT T.Id AS PregenBlog_Id, True AS _from0 FROM CodeFirstDatabase.PregenBlog AS T ) AS T1"); default: throw new InvalidOperationException(); } }
/// <summary> /// Recursively generates <see cref="MemberPath" />s for the members of the types stored in the <paramref name="extent" />. /// </summary> internal static MemberProjectionIndex Create(EntitySetBase extent, EdmItemCollection edmItemCollection) { // We generate the indices for the projected slots as we traverse the metadata. var index = new MemberProjectionIndex(); GatherPartialSignature(index, edmItemCollection, new MemberPath(extent), false); // need not only keys return index; }
/// <summary> /// Gets a view corresponding to the specified extent. /// </summary> /// <param name="extent">The extent.</param> /// <returns>The mapping view, or null if the extent is not associated with a mapping view.</returns> public override DbMappingView GetView(EntitySetBase extent) { if (extent == null) { throw new ArgumentNullException("extent"); } var extentName = extent.EntityContainer.Name + "." + extent.Name; if (extentName == "Хранилище Num_equipmentModelContainer.Customers") { return GetView0(); } if (extentName == "Num_equipmentEntities.Customers") { return GetView1(); } if (extentName == "Хранилище Num_equipmentModelContainer.Firms") { return GetView2(); } if (extentName == "Num_equipmentEntities.Firms") { return GetView3(); } return null; }
/// <summary> /// Creates generated view object for the combination of the <paramref name="extent" /> and the <paramref name="type" />. /// This constructor is used for regular cell-based view generation. /// </summary> internal static GeneratedView CreateGeneratedView( EntitySetBase extent, EdmType type, DbQueryCommandTree commandTree, string eSQL, StorageMappingItemCollection mappingItemCollection, ConfigViewGenerator config) { // If config.GenerateEsql is specified, eSQL must be non-null. // If config.GenerateEsql is false, commandTree is non-null except the case when loading pre-compiled eSQL views. Debug.Assert(!config.GenerateEsql || !String.IsNullOrEmpty(eSQL), "eSQL must be specified"); DiscriminatorMap discriminatorMap = null; if (commandTree != null) { commandTree = ViewSimplifier.SimplifyView(extent, commandTree); // See if the view matches the "discriminated" pattern (allows simplification of generated store commands) if (extent.BuiltInTypeKind == BuiltInTypeKind.EntitySet) { if (DiscriminatorMap.TryCreateDiscriminatorMap((EntitySet)extent, commandTree.Query, out discriminatorMap)) { Debug.Assert(discriminatorMap != null, "discriminatorMap == null after it has been created"); } } } return new GeneratedView(extent, type, commandTree, eSQL, discriminatorMap, mappingItemCollection, config); }
// ObjectStateEntry will not be detached and creation will be handled from ObjectStateManager internal ObjectStateEntry(ObjectStateManager cache, EntitySet entitySet, EntityState state) { DebugCheck.NotNull(cache); _cache = cache; _entitySet = entitySet; _state = state; }
// ObjectStateEntry will not be detached and creation will be handled from ObjectStateManager internal ObjectStateEntry(ObjectStateManager cache, EntitySet entitySet, EntityState state) { Contract.Requires(cache != null); _cache = cache; _entitySet = entitySet; _state = state; }
internal bool TryGetEntityContainer(EntitySetBase item, out EntityContainer container) { if (item != null) { return itemToContainerMap.TryGetValue(item, out container); } container = null; return false; }
/// <summary> /// Creates generated view object for the combination of the <paramref name="extent" /> and the <paramref name="type" />. /// This constructor is used for FK association sets only. /// </summary> internal static GeneratedView CreateGeneratedViewForFKAssociationSet( EntitySetBase extent, EdmType type, DbQueryCommandTree commandTree, StorageMappingItemCollection mappingItemCollection, ConfigViewGenerator config) { return new GeneratedView(extent, type, commandTree, null, null, mappingItemCollection, config); }
// <summary> // Is there a parent child relationship between table1 and table2 ? // </summary> // <param name="table1"> parent table ? </param> // <param name="table2"> child table ? </param> // <param name="constraints"> list of constraints ? </param> // <returns> true if there is at least one constraint </returns> internal bool IsParentChildRelationship( md.EntitySetBase table1, md.EntitySetBase table2, out List <ForeignKeyConstraint> constraints) { LoadRelationships(table1.EntityContainer); LoadRelationships(table2.EntityContainer); var extentPair = new ExtentPair(table1, table2); return(m_parentChildRelationships.TryGetValue(extentPair, out constraints)); }
/// <summary> /// Gets a view corresponding to the specified extent. /// </summary> /// <param name="extent">The extent.</param> /// <returns>The mapping view, or null if the extent is not associated with a mapping view.</returns> public override DbMappingView GetView(EntitySetBase extent) { if (extent == null) { throw new ArgumentNullException("extent"); } var extentName = extent.EntityContainer.Name + "." + extent.Name; return null; }
/// <summary> /// Returns mappings for the given set/type only if the mapping applies also to childEntittyType either via IsTypeOf or explicitly specifying multiple types in mapping fragments. /// </summary> private static IEnumerable<StorageTypeMapping> GetIsTypeOfMappingsForEntitySetAndType( StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType, EntityTypeBase childEntityType) { foreach (var mapping in GetMappingsForEntitySetAndType(mappingCollection, container, entitySet, entityType)) { if (mapping.IsOfTypes.Any(parentType => parentType.IsAssignableFrom(childEntityType)) || mapping.Types.Contains(childEntityType)) { yield return mapping; } } }
// <summary> // Creates an cql block representing the <paramref name="extent" /> (the FROM part). // SELECT is given by <paramref name="slots" />, WHERE by <paramref name="whereClause" /> and AS by // <paramref // name="blockAliasNum" /> // . // </summary> internal ExtentCqlBlock( EntitySetBase extent, CellQuery.SelectDistinct selectDistinct, SlotInfo[] slots, BoolExpression whereClause, CqlIdentifiers identifiers, int blockAliasNum) : base(slots, _emptyChildren, whereClause, identifiers, blockAliasNum) { m_extent = extent; m_nodeTableAlias = identifiers.GetBlockAlias(); m_selectDistinct = selectDistinct; }
/// <summary> /// Gets a view corresponding to the specified extent. /// </summary> /// <param name="extent">The extent.</param> /// <returns>The mapping view, or null if the extent is not associated with a mapping view.</returns> public override DbMappingView GetView(EntitySetBase extent) { if (extent == null) { throw new ArgumentNullException("extent"); } var extentName = extent.EntityContainer.Name + "." + extent.Name; if (extentName == "CodeFirstDatabase.Designation") { return GetView0(); } if (extentName == "CodeFirstDatabase.EmployeeLanguages") { return GetView1(); } if (extentName == "CodeFirstDatabase.Employee") { return GetView2(); } if (extentName == "CodeFirstDatabase.Language") { return GetView3(); } if (extentName == "QTecDataContext.Designations") { return GetView4(); } if (extentName == "QTecDataContext.EmployeeLanguages") { return GetView5(); } if (extentName == "QTecDataContext.Employees") { return GetView6(); } if (extentName == "QTecDataContext.Languages") { return GetView7(); } return null; }
/// <summary> /// Gets a view corresponding to the specified extent. /// </summary> /// <param name="extent">The extent.</param> /// <returns>The mapping view, or null if the extent is not associated with a mapping view.</returns> public override DbMappingView GetView(EntitySetBase extent) { if (extent == null) { throw new ArgumentNullException("extent"); } var extentName = extent.EntityContainer.Name + "." + extent.Name; if (extentName == "CodeFirstDatabase.Category") { return GetView0(); } if (extentName == "CodeFirstDatabase.Location") { return GetView1(); } if (extentName == "CodeFirstDatabase.Review") { return GetView2(); } if (extentName == "DatabaseContext.Categories") { return GetView3(); } if (extentName == "DatabaseContext.Locations") { return GetView4(); } if (extentName == "DatabaseContext.Reviews") { return GetView5(); } if (extentName == "DatabaseContext.Review_Category") { return GetView6(); } if (extentName == "DatabaseContext.Review_Location") { return GetView7(); } return null; }
/// <summary> /// Returns all mapping fragments for the given entity set's types and their parent types. /// </summary> internal static IEnumerable<StorageTypeMapping> GetMappingsForEntitySetAndSuperTypes( StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase childEntityType) { return MetadataHelper.GetTypeAndParentTypesOf(childEntityType, true /*includeAbstractTypes*/).SelectMany( edmType => { var entityTypeBase = edmType as EntityTypeBase; return edmType.EdmEquals(childEntityType) ? GetMappingsForEntitySetAndType(mappingCollection, container, entitySet, entityTypeBase) : GetIsTypeOfMappingsForEntitySetAndType( mappingCollection, container, entitySet, entityTypeBase, childEntityType); }).ToList(); }
public string GetQualifiedPrefix(EntitySetBase item) { Debug.Assert(ModelParentMap != null); string qualifiedPrefix = null; EntityContainer parentContainer; if (ModelParentMap.TryGetEntityContainer(item, out parentContainer)) { qualifiedPrefix = parentContainer.Name; } return qualifiedPrefix; }
/// <Summary> /// The method returns the view for the index given. /// </Summary> public override DbMappingView GetView(EntitySetBase extent) { // do not lock if views are loaded if (extentViews == null) { lock(lockObject) { if (extentViews == null) { LoadViews(); } } } DbMappingView view; extentViews.TryGetValue(GetExtentFullName(extent), out view); return view; }
internal static IEnumerable<StorageTypeMapping> GetMappingsForEntitySetAndType( StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType) { DebugCheck.NotNull(entityType); var containerMapping = GetEntityContainerMap(mappingCollection, container); var extentMap = containerMapping.GetSetMapping(entitySet.Name); //The Set may have no mapping if (extentMap != null) { //for each mapping fragment of Type we are interested in within the given set //Check use of IsOfTypes in Code review foreach (var typeMap in extentMap.TypeMappings.Where(map => map.Types.Union(map.IsOfTypes).Contains(entityType))) { yield return typeMap; } } }
protected virtual void Visit(EntitySetBase entitySetBase) { // this is a switching node, so no object header and footer will be add for this node, // also this Visit won't add the object to the seen list switch (entitySetBase.BuiltInTypeKind) { case BuiltInTypeKind.EntitySet: Visit((EntitySet)entitySetBase); break; case BuiltInTypeKind.AssociationSet: Visit((AssociationSet)entitySetBase); break; default: Debug.Fail( string.Format( CultureInfo.InvariantCulture, "Found type '{0}', did we add a new type?", entitySetBase.BuiltInTypeKind)); break; } }
/// <summary> /// Gets a view corresponding to the specified extent. /// </summary> /// <param name="extent">The extent.</param> /// <returns>The mapping view, or null if the extent is not associated with a mapping view.</returns> public override DbMappingView GetView(EntitySetBase extent) { if (extent == null) { throw new ArgumentNullException("extent"); } var extentName = extent.EntityContainer.Name + "." + extent.Name; if (extentName == "PeopleDedicatedModelStoreContainer.People") { return GetView0(); } if (extentName == "PeopleDedicatedEntities.People") { return GetView1(); } return null; }
internal static IEnumerable<StorageEntityTypeModificationFunctionMapping> GetModificationFunctionMappingsForEntitySetAndType( StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType) { var containerMapping = GetEntityContainerMap(mappingCollection, container); var extentMap = containerMapping.GetSetMapping(entitySet.Name); var entitySetMapping = extentMap as StorageEntitySetMapping; //The Set may have no mapping if (entitySetMapping != null) { if (entitySetMapping != null) //could be association set mapping { foreach ( var v in entitySetMapping.ModificationFunctionMappings.Where(functionMap => functionMap.EntityType.Equals(entityType))) { yield return v; } } } }
// effects: Generates a view for an extent "extent" that belongs to // schema "schema". extentCells are the cells for this extent. // Adds the view corrsponding to the extent to "views" private QueryRewriter GenerateDirectionalViewsForExtent( ViewTarget viewTarget, EntitySetBase extent, CqlIdentifiers identifiers, ViewSet views) { // First normalize the cells in terms of multiconstants, etc // and then generate the view for the extent var context = CreateViewgenContext(extent, viewTarget, identifiers); QueryRewriter queryRewriter = null; if (m_config.GenerateViewsForEachType) { // generate views for each OFTYPE(Extent, Type) combination foreach ( var type in MetadataHelper.GetTypeAndSubtypesOf( extent.ElementType, m_entityContainerMapping.StorageMappingItemCollection.EdmItemCollection, false /*includeAbstractTypes*/)) { if (m_config.IsViewTracing && false == type.Equals(extent.ElementType)) { Helpers.FormatTraceLine("CQL View for {0} and type {1}", extent.Name, type.Name); } queryRewriter = GenerateViewsForExtentAndType(type, context, identifiers, views, ViewGenMode.OfTypeViews); } } else { // generate the view for Extent only queryRewriter = GenerateViewsForExtentAndType(extent.ElementType, context, identifiers, views, ViewGenMode.OfTypeViews); } if (viewTarget == ViewTarget.QueryView) { m_config.SetTimeForFinishedActivity(PerfType.QueryViews); } else { m_config.SetTimeForFinishedActivity(PerfType.UpdateViews); } // cache this rewriter (and context inside it) for future use in FK checking m_queryRewriterCache[extent] = queryRewriter; return queryRewriter; }
private ErrorLog GenerateQueryViewForExtentAndType( CqlIdentifiers identifiers, ViewSet views, EntitySetBase entity, EntityTypeBase type, ViewGenMode mode) { Debug.Assert(mode != ViewGenMode.GenerateAllViews); // Keep track of the mapping exceptions that we have generated var errorLog = new ErrorLog(); if (m_config.IsViewTracing) { Helpers.StringTraceLine(String.Empty); Helpers.StringTraceLine(String.Empty); Helpers.FormatTraceLine( "================= Generating {0} Query View for: {1} ===========================", (mode == ViewGenMode.OfTypeViews) ? "OfType" : "OfTypeOnly", entity.Name); Helpers.StringTraceLine(String.Empty); Helpers.StringTraceLine(String.Empty); } try { // (1) view generation (checks that extents are fully mapped) var context = CreateViewgenContext(entity, ViewTarget.QueryView, identifiers); var queryRewriter = GenerateViewsForExtentAndType(type, context, identifiers, views, mode); } catch (InternalMappingException exception) { // All exceptions have mapping errors in them Debug.Assert(exception.ErrorLog.Count > 0, "Incorrectly created mapping exception"); errorLog.Merge(exception.ErrorLog); } return errorLog; }
internal virtual void NotifyItemIdentityChanged(EntitySetBase item, string initialIdentity) { _baseEntitySets.Source.HandleIdentityChange(item, initialIdentity); }
internal static bool IsEntitySet(EntitySetBase entitySetBase) { return(BuiltInTypeKind.EntitySet == entitySetBase.BuiltInTypeKind); }
// effects: Returns a context corresponding to extent (if one does not exist, creates one) private ViewgenContext CreateViewgenContext(EntitySetBase extent, ViewTarget viewTarget, CqlIdentifiers identifiers) { QueryRewriter queryRewriter; if (!m_queryRewriterCache.TryGetValue(extent, out queryRewriter)) { // collect the cells that belong to this extent (just a few of them since we segment the mapping first) var cellsForExtent = m_cellGroup.Where(c => c.GetLeftQuery(viewTarget).Extent == extent); return new ViewgenContext( viewTarget, extent, cellsForExtent, identifiers, m_config, m_queryDomainMap, m_updateDomainMap, m_entityContainerMapping); } else { return queryRewriter.ViewgenContext; } }
internal static bool IsRelationshipSet(EntitySetBase entitySetBase) { return(BuiltInTypeKind.AssociationSet == entitySetBase.BuiltInTypeKind); }
public override DbMappingView GetView(EntitySetBase extent) { throw new NotImplementedException(); }
internal void AddEntitySetBase(EntitySetBase entitySetBase) { _baseEntitySets.Source.Add(entitySetBase); }