/// <summary> /// Gets the provider manifest for given provider manifest token. /// </summary> /// <param name="manifestToken">The provider manifest token.</param> /// <returns><see cref="DbProviderManifest"/> for a given token.</returns> protected override System.Data.Entity.Core.Common.DbProviderManifest GetDbProviderManifest(string manifestToken) { string providerInvariantName; string realToken; // check if the name of the wrapped provider is specified in the token int p = manifestToken.IndexOf(';'); if (p < 0) { // wrapped provider is not in the token - use default one realToken = manifestToken; providerInvariantName = this.DefaultWrappedProviderName; } else { // extract provider name from the token providerInvariantName = manifestToken.Substring(0, p); realToken = manifestToken.Substring(p + 1); } // retrieve wrapped provider manifest System.Data.Entity.Core.Common.DbProviderServices services = GetProviderServicesByName(providerInvariantName); System.Data.Entity.Core.Common.DbProviderManifest wrappedProviderManifest = services.GetProviderManifest(realToken); System.Data.Entity.Core.Common.DbProviderManifest wrapperManifest = this.CreateProviderManifest(providerInvariantName, wrappedProviderManifest); return(wrapperManifest); }
public override IEnumerable <MigrationStatement> Generate(IEnumerable <MigrationOperation> migrationOperations, string providerManifestToken) { MySqlConnection con = new MySqlConnection(); List <MigrationStatement> stmts = new List <MigrationStatement>(); _providerManifestToken = providerManifestToken; _providerManifest = System.Data.Entity.Core.Common.DbProviderServices.GetProviderServices(con).GetProviderManifest(providerManifestToken); //verify if there is one or more add/alter column operation, if there is then look for primary key operations. Alter in case that the user wants to change the current PK column if ((from cols in migrationOperations.OfType <AddColumnOperation>() select cols).Count() > 0 || (from cols in migrationOperations.OfType <AlterColumnOperation>() select cols).Count() > 0) { _pkOperations = (from pks in migrationOperations.OfType <AddPrimaryKeyOperation>() select pks).ToList(); } foreach (MigrationOperation op in migrationOperations) { if (!_dispatcher.ContainsKey(op.GetType().Name)) { throw new NotImplementedException(op.GetType().Name); } OpDispatcher opdis = _dispatcher[op.GetType().Name]; stmts.Add(opdis(op)); } if (_specialStmts.Count > 0) { foreach (var item in _specialStmts) { stmts.Add(item); } } return(stmts); }
public virtual void Configure( EntityTypeModificationFunctionMapping modificationStoredProcedureMapping, DbProviderManifest providerManifest) { DebugCheck.NotNull(modificationStoredProcedureMapping); DebugCheck.NotNull(providerManifest); if (_insertModificationStoredProcedureConfiguration != null) { _insertModificationStoredProcedureConfiguration .Configure(modificationStoredProcedureMapping.InsertFunctionMapping, providerManifest); } if (_updateModificationStoredProcedureConfiguration != null) { _updateModificationStoredProcedureConfiguration .Configure(modificationStoredProcedureMapping.UpdateFunctionMapping, providerManifest); } if (_deleteModificationStoredProcedureConfiguration != null) { _deleteModificationStoredProcedureConfiguration .Configure(modificationStoredProcedureMapping.DeleteFunctionMapping, providerManifest); } }
public DatabaseMappingGenerator(DbProviderInfo providerInfo, DbProviderManifest providerManifest) { DebugCheck.NotNull(providerInfo); DebugCheck.NotNull(providerManifest); _providerInfo = providerInfo; _providerManifest = providerManifest; }
// <summary> // The constructor for PrimitiveType, it takes in a CLR type containing the identity information // </summary> // <param name="clrType"> The CLR type object for this primitive type </param> // <param name="baseType"> The base type for this primitive type </param> // <param name="providerManifest"> The ProviderManifest of the provider of this type </param> internal PrimitiveType( Type clrType, PrimitiveType baseType, DbProviderManifest providerManifest) : this(Check.NotNull(clrType, "clrType").Name, clrType.NestingNamespace(), DataSpace.OSpace, baseType, providerManifest) { Debug.Assert(clrType == ClrEquivalentType, "not equivalent to ClrEquivalentType"); }
internal DbModel(DbProviderInfo providerInfo, DbProviderManifest providerManifest) { DebugCheck.NotNull(providerInfo); DebugCheck.NotNull(providerManifest); _databaseMapping = new DbDatabaseMapping().Initialize( EdmModel.CreateConceptualModel(), EdmModel.CreateStoreModel(providerInfo, providerManifest)); }
/// <summary> /// The constructor for PrimitiveType, it takes in a CLR type containing the identity information /// </summary> /// <param name="clrType"> The CLR type object for this primitive type </param> /// <param name="baseType"> The base type for this primitive type </param> /// <param name="providerManifest"> The ProviderManifest of the provider of this type </param> internal PrimitiveType( Type clrType, PrimitiveType baseType, DbProviderManifest providerManifest) : this(EntityUtil.GenericCheckArgumentNull(clrType, "clrType").Name, clrType.Namespace, DataSpace.OSpace, baseType, providerManifest) { Debug.Assert(clrType == ClrEquivalentType, "not equivalent to ClrEquivalentType"); }
public DmlFunctionSqlGenerator(DbProviderManifest providerManifest) { DebugCheck.NotNull(providerManifest); var sqlManifest = providerManifest as SqlProviderManifest; if (sqlManifest == null) { throw new ArgumentException(Strings.Mapping_Provider_WrongManifestType(typeof(SqlProviderManifest))); } _sqlGenerator = new SqlGenerator(sqlManifest.SqlVersion); }
/// <summary> /// The constructor for PrimitiveType. It takes the required information to identify this type. /// </summary> /// <param name="name"> The name of this type </param> /// <param name="namespaceName"> The namespace name of this type </param> /// <param name="version"> The version of this type </param> /// <param name="dataSpace"> dataSpace in which this primitive type belongs to </param> /// <param name="baseType"> The primitive type that this type is derived from </param> /// <param name="providerManifest"> The ProviderManifest of the provider of this type </param> /// <exception cref="System.ArgumentNullException">Thrown if name, namespaceName, version, baseType or providerManifest arguments are null</exception> internal PrimitiveType( string name, string namespaceName, DataSpace dataSpace, PrimitiveType baseType, DbProviderManifest providerManifest) : base(name, namespaceName, dataSpace) { EntityUtil.GenericCheckArgumentNull(baseType, "baseType"); EntityUtil.GenericCheckArgumentNull(providerManifest, "providerManifest"); BaseType = baseType; Initialize(this, baseType.PrimitiveTypeKind, providerManifest); }
internal PrimitiveType( string name, string namespaceName, DataSpace dataSpace, PrimitiveType baseType, DbProviderManifest providerManifest) : base(name, namespaceName, dataSpace) { Check.NotNull(baseType, "baseType"); Check.NotNull(providerManifest, "providerManifest"); BaseType = baseType; Initialize(this, baseType.PrimitiveTypeKind, providerManifest); }
protected override void ConfigureColumn(EdmProperty column, EntityType table, DbProviderManifest providerManifest) { if (IsRowVersion != null && IsRowVersion.Value) { ColumnType = ColumnType ?? "rowversion"; } base.ConfigureColumn(column, table, providerManifest); if (IsRowVersion != null && IsRowVersion.Value) { column.MaxLength = null; } }
internal override void Configure( IEnumerable<Tuple<DbEdmPropertyMapping, DbTableMetadata>> propertyMappings, DbProviderManifest providerManifest, bool allowOverride = false) { base.Configure(propertyMappings, providerManifest, allowOverride); propertyMappings .Each( pm => { if (IsRowVersion != null) { pm.Item1.Column.Facets.MaxLength = null; } }); }
internal override void Configure( IEnumerable<Tuple<ColumnMappingBuilder, EntityType>> propertyMappings, DbProviderManifest providerManifest, bool allowOverride = false) { base.Configure(propertyMappings, providerManifest, allowOverride); propertyMappings .Each( pm => { if (IsRowVersion != null) { pm.Item1.ColumnProperty.MaxLength = null; } }); }
public override string GenerateProcedureBody(ICollection <DbModificationCommandTree> commandTrees, string rowsAffectedParameter, string providerManifestToken) { MySqlConnection con = new MySqlConnection(); MigrationStatement stmt = new MigrationStatement(); _providerManifest = System.Data.Entity.Core.Common.DbProviderServices.GetProviderServices(con).GetProviderManifest(providerManifestToken); var cmdStr = ""; SqlGenerator generator = new SelectGenerator(); foreach (var commandTree in commandTrees) { switch (commandTree.CommandTreeKind) { case DbCommandTreeKind.Insert: generator = new InsertGenerator(); cmdStr = generator.GenerateSQL(commandTree); break; case DbCommandTreeKind.Delete: generator = new DeleteGenerator(); cmdStr = generator.GenerateSQL(commandTree); break; case DbCommandTreeKind.Update: generator = new UpdateGenerator(); cmdStr = generator.GenerateSQL(commandTree); break; case DbCommandTreeKind.Query: generator = new SelectGenerator(); cmdStr = generator.GenerateSQL(commandTree); break; case DbCommandTreeKind.Function: generator = new FunctionGenerator(); cmdStr = generator.GenerateSQL(commandTree); break; } stmt.Sql += cmdStr.Replace("dbo.", "") + ";"; } return(stmt.Sql); }
/// <summary> /// Converts a property from SOM to metadata /// </summary> /// <param name="somProperty">The SOM element to process</param> /// <param name="providerManifest">The provider manifest to be used for conversion</param> /// <param name="convertedItemCache">The item collection for currently existing metadata objects</param> /// <param name="newGlobalItems">The new GlobalItem objects that are created as a result of this conversion</param> /// <returns>The property object resulting from the convert</returns> private static EdmProperty ConvertToProperty( Som.StructuredProperty somProperty, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems) { EdmProperty property; // Get the appropriate type object for this type, for primitive and enum types, get the facet values for the type // property as a type usage object as well TypeUsage typeUsage = null; var scalarType = somProperty.Type as Som.ScalarType; if (scalarType != null && somProperty.Schema.DataModel != Som.SchemaDataModelOption.EntityDataModel) { // parsing ssdl typeUsage = somProperty.TypeUsage; UpdateSentinelValuesInFacets(ref typeUsage); } else { EdmType propertyType; if (scalarType != null) { Debug.Assert(somProperty.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType); // try to get the instance of the primitive type from the item collection so that it back pointer is set. propertyType = convertedItemCache.ItemCollection.GetItem<PrimitiveType>(somProperty.TypeUsage.EdmType.FullName); } else { propertyType = (EdmType)LoadSchemaElement(somProperty.Type, providerManifest, convertedItemCache, newGlobalItems); } if (somProperty.CollectionKind != CollectionKind.None) { typeUsage = TypeUsage.Create(new CollectionType(propertyType)); } else { var enumType = scalarType == null ? somProperty.Type as Som.SchemaEnumType : null; typeUsage = TypeUsage.Create(propertyType); if (enumType != null) { somProperty.EnsureEnumTypeFacets(convertedItemCache, newGlobalItems); } if (somProperty.TypeUsage != null) { ApplyTypePropertyFacets(somProperty.TypeUsage, ref typeUsage); } } } PopulateGeneralFacets(somProperty, ref typeUsage); property = new EdmProperty(somProperty.Name, typeUsage); // Extract the optional Documentation if (somProperty.Documentation != null) { property.Documentation = ConvertToDocumentation(somProperty.Documentation); } AddOtherContent(somProperty, property); return property; }
/// <summary> /// Converts a navigation property from SOM to metadata /// </summary> /// <param name="declaringEntityType">entity type on which this navigation property was declared</param> /// <param name="somNavigationProperty">The SOM element to process</param> /// <param name="providerManifest">The provider manifest to be used for conversion</param> /// <param name="convertedItemCache">The item collection for currently existing metadata objects</param> /// <param name="newGlobalItems">The new GlobalItem objects that are created as a result of this conversion</param> /// <returns>The property object resulting from the convert</returns> private static NavigationProperty ConvertToNavigationProperty( EntityType declaringEntityType, Som.NavigationProperty somNavigationProperty, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems) { // Navigation properties cannot be primitive types, so we can ignore the possibility of having primitive type // facets var toEndEntityType = (EntityType)LoadSchemaElement( somNavigationProperty.Type, providerManifest, convertedItemCache, newGlobalItems); EdmType edmType = toEndEntityType; // Also load the relationship Type that this navigation property represents var relationshipType = (AssociationType)LoadSchemaElement( (Som.Relationship)somNavigationProperty.Relationship, providerManifest, convertedItemCache, newGlobalItems); Som.IRelationshipEnd somRelationshipEnd = null; somNavigationProperty.Relationship.TryGetEnd(somNavigationProperty.ToEnd.Name, out somRelationshipEnd); if (somRelationshipEnd.Multiplicity == RelationshipMultiplicity.Many) { edmType = toEndEntityType.GetCollectionType(); } else { Debug.Assert(somRelationshipEnd.Multiplicity != RelationshipMultiplicity.Many); edmType = toEndEntityType; } TypeUsage typeUsage; if (somRelationshipEnd.Multiplicity == RelationshipMultiplicity.One) { typeUsage = TypeUsage.Create( edmType, new FacetValues { Nullable = false }); } else { typeUsage = TypeUsage.Create(edmType); } // We need to make sure that both the ends of the relationtype are initialized. If there are not, then we should // initialize them here InitializeAssociationEndMember(relationshipType, somNavigationProperty.ToEnd, toEndEntityType); InitializeAssociationEndMember(relationshipType, somNavigationProperty.FromEnd, declaringEntityType); // The type of the navigation property must be a ref or collection depending on which end they belong to var navigationProperty = new NavigationProperty(somNavigationProperty.Name, typeUsage); navigationProperty.RelationshipType = relationshipType; navigationProperty.ToEndMember = (RelationshipEndMember)relationshipType.Members[somNavigationProperty.ToEnd.Name]; navigationProperty.FromEndMember = (RelationshipEndMember)relationshipType.Members[somNavigationProperty.FromEnd.Name]; // Extract the optional Documentation if (somNavigationProperty.Documentation != null) { navigationProperty.Documentation = ConvertToDocumentation(somNavigationProperty.Documentation); } AddOtherContent(somNavigationProperty, navigationProperty); return navigationProperty; }
/// <summary> /// Creates the command definition wrapper for a given provider manifest and command tree. /// </summary> /// <param name="providerManifest">The provider manifest.</param> /// <param name="commandTree">The command tree.</param> /// <returns><see cref="DbCommandDefinition"/> object.</returns> protected override System.Data.Entity.Core.Common.DbCommandDefinition CreateDbCommandDefinition(System.Data.Entity.Core.Common.DbProviderManifest providerManifest, System.Data.Entity.Core.Common.CommandTrees.DbCommandTree commandTree) { var wrapperManifest = (DbProviderManifestWrapper)providerManifest; var createDbCommandDefinitionFunction = this.GetCreateDbCommandDefinitionFunction(wrapperManifest.WrappedProviderManifestInvariantName); System.Data.Entity.Core.Common.DbCommandDefinition definition = createDbCommandDefinitionFunction(wrapperManifest.WrappedProviderManifest, commandTree); return(this.CreateCommandDefinitionWrapper(definition, commandTree)); }
/// <summary> /// Converts an association set from SOM to metadata /// </summary> /// <param name="relationshipSet">The SOM element to process</param> /// <param name="providerManifest">The provider manifest to be used for conversion</param> /// <param name="convertedItemCache">The item collection for currently existing metadata objects</param> /// <param name="newGlobalItems">The new GlobalItem objects that are created as a result of this conversion</param> /// <param name="container"></param> /// <returns>The association set object resulting from the convert</returns> private static AssociationSet ConvertToAssociationSet( Som.EntityContainerRelationshipSet relationshipSet, DbProviderManifest providerManifest, ConversionCache convertedItemCache, EntityContainer container, Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems) { Debug.Assert(relationshipSet.Relationship.RelationshipKind == RelationshipKind.Association); var associationType = (AssociationType)LoadSchemaElement( (Som.SchemaType)relationshipSet.Relationship, providerManifest, convertedItemCache, newGlobalItems); var associationSet = new AssociationSet(relationshipSet.Name, associationType); foreach (var end in relationshipSet.Ends) { //-- need the EntityType for the end var endEntityType = (EntityType)LoadSchemaElement( end.EntitySet.EntityType, providerManifest, convertedItemCache, newGlobalItems); //-- need to get the end member var endMember = (AssociationEndMember)associationType.Members[end.Name]; //-- create the end var associationSetEnd = new AssociationSetEnd( GetEntitySet(end.EntitySet, container), associationSet, endMember); AddOtherContent(end, associationSetEnd); associationSet.AddAssociationSetEnd(associationSetEnd); // Extract optional Documentation from the end element if (end.Documentation != null) { associationSetEnd.Documentation = ConvertToDocumentation(end.Documentation); } } // Extract the optional Documentation if (relationshipSet.Documentation != null) { associationSet.Documentation = ConvertToDocumentation(relationshipSet.Documentation); } AddOtherContent(relationshipSet, associationSet); return associationSet; }
public static IList<EdmSchemaError> ParseAndValidate( IEnumerable<XmlReader> xmlReaders, IEnumerable<string> sourceFilePaths, SchemaDataModelOption dataModel, DbProviderManifest providerManifest, out IList<Schema> schemaCollection) { return ParseAndValidate( xmlReaders, sourceFilePaths, dataModel, NoOpAttributeValueNotification, NoOpAttributeValueNotification, delegate { return providerManifest == null ? MetadataItem.EdmProviderManifest : providerManifest; }, out schemaCollection); }
/// <summary> /// Perform initialization that's common across all constructors /// </summary> /// <param name="primitiveType"> The primitive type to initialize </param> /// <param name="primitiveTypeKind"> The primitive type kind of this primitive type </param> /// <param name="providerManifest"> The ProviderManifest of the provider of this type </param> internal static void Initialize( PrimitiveType primitiveType, PrimitiveTypeKind primitiveTypeKind, DbProviderManifest providerManifest) { primitiveType._primitiveTypeKind = primitiveTypeKind; primitiveType._providerManifest = providerManifest; }
public static IEnumerable<Facet> InferSsdlFacetsForCsdlProperty(this EdmProperty csdlProperty, DbProviderManifest providerManifest) { var storeType = csdlProperty.GetStoreTypeUsage(providerManifest); Dictionary<string, Facet> storeFacetLookup = storeType.Facets.ToDictionary(f => f.Name, f => f); // Note that there are some facets that exist in the C-side but not in the store side (Collation/ConcurrencyMode) // Also the IsStrict facet can exist on the C-side but should not be used on the S-side despite the fact that e.g. SqlServer.geometry defines that facet return csdlProperty.TypeUsage.Facets.Where( f => (storeFacetLookup.ContainsKey(f.Name) && storeFacetLookup[f.Name].Description.IsConstant == false && !"IsStrict".Equals(f.Name, StringComparison.Ordinal))); }
private static TypeUsage GetStoreTypeUsage(this EdmMember edmMember, DbProviderManifest providerManifest) { TypeUsage storeType = null; var conceptualType = edmMember.TypeUsage; Debug.Assert(conceptualType != null, "EdmMember's TypeUsage is null"); if (conceptualType != null) { // if the EDM type is an enum, then we need to pass in the underlying type to the GetStoreType API. var enumType = conceptualType.EdmType as EnumType; storeType = (enumType != null) ? providerManifest.GetStoreType(TypeUsage.CreateDefaultTypeUsage(enumType.UnderlyingType)) : providerManifest.GetStoreType(conceptualType); } return storeType; }
private static EdmFunction ConvertToFunction( Som.Function somFunction, DbProviderManifest providerManifest, ConversionCache convertedItemCache, EntityContainer functionImportEntityContainer, Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems) { // If we already have it, don't bother converting GlobalItem globalItem = null; // if we are converted the function import, we need not check the global items collection, // since the function imports are local to the entity container if (!somFunction.IsFunctionImport && newGlobalItems.TryGetValue(somFunction, out globalItem)) { return (EdmFunction)globalItem; } var areConvertingForProviderManifest = somFunction.Schema.DataModel == Som.SchemaDataModelOption.ProviderManifestModel; var returnParameters = new List<FunctionParameter>(); if (somFunction.ReturnTypeList != null) { var i = 0; foreach (var somReturnType in somFunction.ReturnTypeList) { var returnType = GetFunctionTypeUsage( somFunction is Som.ModelFunction, somFunction, somReturnType, providerManifest, areConvertingForProviderManifest, somReturnType.Type, somReturnType.CollectionKind, somReturnType.IsRefType /*isRefType*/, convertedItemCache, newGlobalItems); if (null != returnType) { // Create the return parameter object, need to set the declaring type explicitly on the return parameter // because we aren't adding it to the members collection var modifier = i == 0 ? string.Empty : i.ToString(CultureInfo.InvariantCulture); i++; var returnParameter = new FunctionParameter( EdmConstants.ReturnType + modifier, returnType, ParameterMode.ReturnValue); AddOtherContent(somReturnType, returnParameter); returnParameters.Add(returnParameter); } else { return null; } } } // this case must be second to avoid calling somFunction.Type when returnTypeList has more than one element. else if (somFunction.Type != null) { var returnType = GetFunctionTypeUsage( somFunction is Som.ModelFunction, somFunction, null, providerManifest, areConvertingForProviderManifest, somFunction.Type, somFunction.CollectionKind, somFunction.IsReturnAttributeReftype /*isRefType*/, convertedItemCache, newGlobalItems); if (null != returnType) { // Create the return parameter object, need to set the declaring type explicitly on the return parameter // because we aren't adding it to the members collection returnParameters.Add(new FunctionParameter(EdmConstants.ReturnType, returnType, ParameterMode.ReturnValue)); } else { //Return type was specified but we could not find a type usage return null; } } string functionNamespace; EntitySet[] entitySets = null; if (somFunction.IsFunctionImport) { var somFunctionImport = (Som.FunctionImportElement)somFunction; functionNamespace = somFunctionImport.Container.Name; if (null != somFunctionImport.EntitySet) { EntityContainer entityContainer; Debug.Assert( somFunctionImport.ReturnTypeList == null || somFunctionImport.ReturnTypeList.Count == 1, "EntitySet cannot be specified on a FunctionImport if there are multiple ReturnType children"); Debug.Assert( functionImportEntityContainer != null, "functionImportEntityContainer must be specified during function import conversion"); entityContainer = functionImportEntityContainer; entitySets = new[] { GetEntitySet(somFunctionImport.EntitySet, entityContainer) }; } else if (null != somFunctionImport.ReturnTypeList) { Debug.Assert( functionImportEntityContainer != null, "functionImportEntityContainer must be specified during function import conversion"); var entityContainer = functionImportEntityContainer; entitySets = somFunctionImport.ReturnTypeList .Select( returnType => null != returnType.EntitySet ? GetEntitySet(returnType.EntitySet, functionImportEntityContainer) : null) .ToArray(); } } else { functionNamespace = somFunction.Namespace; } var parameters = new List<FunctionParameter>(); foreach (var somParameter in somFunction.Parameters) { var parameterType = GetFunctionTypeUsage( somFunction is Som.ModelFunction, somFunction, somParameter, providerManifest, areConvertingForProviderManifest, somParameter.Type, somParameter.CollectionKind, somParameter.IsRefType, convertedItemCache, newGlobalItems); if (parameterType == null) { return null; } var parameter = new FunctionParameter( somParameter.Name, parameterType, GetParameterMode(somParameter.ParameterDirection)); AddOtherContent(somParameter, parameter); if (somParameter.Documentation != null) { parameter.Documentation = ConvertToDocumentation(somParameter.Documentation); } parameters.Add(parameter); } var function = new EdmFunction( somFunction.Name, functionNamespace, GetDataSpace(providerManifest), new EdmFunctionPayload { Schema = somFunction.DbSchema, StoreFunctionName = somFunction.StoreFunctionName, CommandText = somFunction.CommandText, EntitySets = entitySets, IsAggregate = somFunction.IsAggregate, IsBuiltIn = somFunction.IsBuiltIn, IsNiladic = somFunction.IsNiladicFunction, IsComposable = somFunction.IsComposable, IsFromProviderManifest = areConvertingForProviderManifest, IsFunctionImport = somFunction.IsFunctionImport, ReturnParameters = returnParameters.ToArray(), Parameters = parameters.ToArray(), ParameterTypeSemantics = somFunction.ParameterTypeSemantics, }); // Add this function to new global items, only if it is not a function import if (!somFunction.IsFunctionImport) { newGlobalItems.Add(somFunction, function); } //Check if we already converted functions since we are loading it from //ssdl we could see functions many times. GlobalItem returnFunction = null; Debug.Assert( !convertedItemCache.ItemCollection.TryGetValue(function.Identity, false, out returnFunction), "Function duplicates must be checked by som"); // Extract the optional Documentation if (somFunction.Documentation != null) { function.Documentation = ConvertToDocumentation(somFunction.Documentation); } AddOtherContent(somFunction, function); return function; }
internal static MetadataItem LoadSchemaElement( Som.SchemaType element, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems) { Debug.Assert(providerManifest != null, "This will make the dataspace to be default SSpace"); // Try to fetch from the collection first GlobalItem item; Debug.Assert( !convertedItemCache.ItemCollection.TryGetValue(element.FQName, false, out item), "Som should have checked for duplicate items"); // Try to fetch in our collection of new GlobalItems if (newGlobalItems.TryGetValue(element, out item)) { return item; } var entityContainer = element as Som.EntityContainer; // Perform different conversion depending on the type of the SOM object if (entityContainer != null) { item = ConvertToEntityContainer( entityContainer, providerManifest, convertedItemCache, newGlobalItems); } else if (element is Som.SchemaEntityType) { item = ConvertToEntityType( (Som.SchemaEntityType)element, providerManifest, convertedItemCache, newGlobalItems); } else if (element is Som.Relationship) { item = ConvertToAssociationType( (Som.Relationship)element, providerManifest, convertedItemCache, newGlobalItems); } else if (element is Som.SchemaComplexType) { item = ConvertToComplexType( (Som.SchemaComplexType)element, providerManifest, convertedItemCache, newGlobalItems); } else if (element is Som.Function) { item = ConvertToFunction( (Som.Function)element, providerManifest, convertedItemCache, null, newGlobalItems); } else if (element is Som.SchemaEnumType) { item = ConvertToEnumType((Som.SchemaEnumType)element, newGlobalItems); } else { // the only type we don't handle is the ProviderManifest TypeElement // if it is anything else, it is probably a mistake Debug.Assert( element is Som.TypeElement && element.Schema.DataModel == Som.SchemaDataModelOption.ProviderManifestModel, "Unknown Type in somschema"); return null; } return item; }
/// <summary> /// create the database command definition. /// </summary> /// <param name="providerManifest">The provider manifest.</param> /// <param name="commandTree">The command tree.</param> /// <returns>the command definition.</returns> protected override System.Data.Entity.Core.Common.DbCommandDefinition CreateDbCommandDefinition(System.Data.Entity.Core.Common.DbProviderManifest providerManifest, DbCommandTree commandTree) { var cmdDef = _tail.CreateCommandDefinition(providerManifest, commandTree); var cmd = cmdDef.CreateCommand(); Debug.Assert(cmd != null, "cmd != null"); return(CreateCommandDefinition(new ProfiledDbCommand(cmd, cmd.Connection, MiniProfiler.Current))); }
/// <summary> /// Creates the provider manifest wrapper. /// </summary> /// <param name="providerInvariantName">Provider invariant name.</param> /// <param name="providerManifest">The provider manifest to be wrapped.</param> /// <returns><see cref="DbProviderManifest"/> wrapper for given provider invariant name wrapping given provider manifest.</returns> public virtual System.Data.Entity.Core.Common.DbProviderManifest CreateProviderManifest(string providerInvariantName, System.Data.Entity.Core.Common.DbProviderManifest providerManifest) { return(new DbProviderManifestWrapper( this.ProviderInvariantName, providerInvariantName, providerManifest)); }
/// <summary>Creates a command definition object for the specified provider manifest and command tree.</summary> /// <returns>An executable command definition object.</returns> /// <param name="providerManifest">Provider manifest previously retrieved from the store provider.</param> /// <param name="commandTree">Command tree for the statement.</param> protected abstract DbCommandDefinition CreateDbCommandDefinition( DbProviderManifest providerManifest, DbCommandTree commandTree);
public ModificationFunctionMappingGenerator(DbProviderManifest providerManifest) : base(providerManifest) { }
/// <summary> /// Initializes a new instance of the DbProviderManifestWrapper class. /// </summary> /// <param name="wrapperProviderInvariantName">Wrapper provider invariant name.</param> /// <param name="providerInvariantName">Provider invariant name.</param> /// <param name="wrappedProviderManifest">The wrapped provider manifest.</param> public DbProviderManifestWrapper(string wrapperProviderInvariantName, string providerInvariantName, System.Data.Entity.Core.Common.DbProviderManifest wrappedProviderManifest) { this.wrapperProviderInvariantName = wrapperProviderInvariantName; this.providerInvariantName = providerInvariantName; this.wrappedProviderManifest = wrappedProviderManifest; }
public static string GetStoreType(this EdmMember edmMember, DbProviderManifest providerManifest) { var storeType = edmMember.GetStoreTypeUsage(providerManifest); if (storeType != null && storeType.EdmType != null && storeType.EdmType.Name != null) { return storeType.EdmType.Name.TrimStart('.'); } return String.Empty; }
private static void LoadEntityTypePhase2( Som.SchemaEntityType element, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems) { var entityType = (EntityType)newGlobalItems[element]; // Since Navigation properties are internal and not part of member collection, we // need to initialize the base class first before we start adding the navigation property // this will ensure that all the base navigation properties are initialized foreach (var somNavigationProperty in element.NavigationProperties) { entityType.AddMember( ConvertToNavigationProperty( entityType, somNavigationProperty, providerManifest, convertedItemCache, newGlobalItems)); } }
internal DbProviderManifest GetProviderManifest(Action<string, ErrorCode, EdmSchemaErrorSeverity> addError) { if (_providerManifest == null) { _providerManifest = _providerManifestNeeded(addError); } return _providerManifest; }
/// <summary> /// Converts an complex type from SOM to metadata /// </summary> /// <param name="element">The SOM element to process</param> /// <param name="providerManifest">The provider manifest to be used for conversion</param> /// <param name="convertedItemCache">The item collection for currently existing metadata objects</param> /// <param name="newGlobalItems">The new GlobalItem objects that are created as a result of this conversion</param> /// <returns>The complex type object resulting from the convert</returns> private static ComplexType ConvertToComplexType( Som.SchemaComplexType element, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems) { var complexType = new ComplexType( element.Name, element.Namespace, GetDataSpace(providerManifest)); newGlobalItems.Add(element, complexType); foreach (var somProperty in element.Properties) { complexType.AddMember( ConvertToProperty( somProperty, providerManifest, convertedItemCache, newGlobalItems)); } // set the abstract and sealed type values for the entity type complexType.Abstract = element.IsAbstract; if (element.BaseType != null) { complexType.BaseType = (EdmType)(LoadSchemaElement( element.BaseType, providerManifest, convertedItemCache, newGlobalItems)); } // Extract the optional Documentation if (element.Documentation != null) { complexType.Documentation = ConvertToDocumentation(element.Documentation); } AddOtherContent(element, complexType); return complexType; }
protected virtual void Visit(DbProviderManifest providerManifest) { }
private static AssociationType ConvertToAssociationType( Som.Relationship element, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems) { Debug.Assert(element.RelationshipKind == RelationshipKind.Association); var associationType = new AssociationType( element.Name, element.Namespace, element.IsForeignKey, GetDataSpace(providerManifest)); newGlobalItems.Add(element, associationType); foreach (Som.RelationshipEnd end in element.Ends) { Som.SchemaType entityTypeElement = end.Type; var endEntityType = (EntityType)LoadSchemaElement( entityTypeElement, providerManifest, convertedItemCache, newGlobalItems); var endMember = InitializeAssociationEndMember(associationType, end, endEntityType); AddOtherContent(end, endMember); // Loop through and convert the operations foreach (var operation in end.Operations) { // Process only the ones that we recognize if (operation.Operation != Som.Operation.Delete) { continue; } // Determine the action for this operation var action = OperationAction.None; switch (operation.Action) { case Som.Action.Cascade: action = OperationAction.Cascade; break; case Som.Action.None: action = OperationAction.None; break; default: Debug.Fail("Operation action not supported."); break; } endMember.DeleteBehavior = action; } // Extract optional Documentation from the end element if (end.Documentation != null) { endMember.Documentation = ConvertToDocumentation(end.Documentation); } } Debug.Assert(associationType.ReferentialConstraints.Count == 0, "This must never have been initialized"); for (var i = 0; i < element.Constraints.Count; i++) { var constraint = element.Constraints[i]; var fromMember = (AssociationEndMember)associationType.Members[constraint.PrincipalRole.Name]; var toMember = (AssociationEndMember)associationType.Members[constraint.DependentRole.Name]; var fromEntityType = ((RefType)fromMember.TypeUsage.EdmType).ElementType; var toEntityType = ((RefType)toMember.TypeUsage.EdmType).ElementType; var referentialConstraint = new ReferentialConstraint( fromMember, toMember, GetProperties(fromEntityType, constraint.PrincipalRole.RoleProperties), GetProperties(toEntityType, constraint.DependentRole.RoleProperties)); // Attach the optional Documentation if (constraint.Documentation != null) { referentialConstraint.Documentation = ConvertToDocumentation(constraint.Documentation); } if (constraint.PrincipalRole.Documentation != null) { referentialConstraint.FromRole.Documentation = ConvertToDocumentation(constraint.PrincipalRole.Documentation); } if (constraint.DependentRole.Documentation != null) { referentialConstraint.ToRole.Documentation = ConvertToDocumentation(constraint.DependentRole.Documentation); } associationType.AddReferentialConstraint(referentialConstraint); AddOtherContent(element.Constraints[i], referentialConstraint); } // Extract the optional Documentation if (element.Documentation != null) { associationType.Documentation = ConvertToDocumentation(element.Documentation); } AddOtherContent(element, associationType); return associationType; }
/// <summary> /// Converts an entity container from SOM to metadata /// </summary> /// <param name="element">The SOM element to process</param> /// <param name="providerManifest">The provider manifest to be used for conversion</param> /// <param name="convertedItemCache">The item collection for currently existing metadata objects</param> /// <param name="newGlobalItems">The new GlobalItem objects that are created as a result of this conversion</param> /// <returns>The entity container object resulting from the convert</returns> private static EntityContainer ConvertToEntityContainer( Som.EntityContainer element, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems) { // Creating a new entity container object and populate with converted entity set objects var entityContainer = new EntityContainer(element.Name, GetDataSpace(providerManifest)); newGlobalItems.Add(element, entityContainer); foreach (var entitySet in element.EntitySets) { entityContainer.AddEntitySetBase( ConvertToEntitySet( entitySet, providerManifest, convertedItemCache, newGlobalItems)); } // Populate with converted relationship set objects foreach (var relationshipSet in element.RelationshipSets) { Debug.Assert( relationshipSet.Relationship.RelationshipKind == RelationshipKind.Association, "We do not support containment set"); entityContainer.AddEntitySetBase( ConvertToAssociationSet( relationshipSet, providerManifest, convertedItemCache, entityContainer, newGlobalItems)); } // Populate with converted function imports foreach (var functionImport in element.FunctionImports) { entityContainer.AddFunctionImport( ConvertToFunction( functionImport, providerManifest, convertedItemCache, entityContainer, newGlobalItems)); } // Extract the optional Documentation if (element.Documentation != null) { entityContainer.Documentation = ConvertToDocumentation(element.Documentation); } AddOtherContent(element, entityContainer); return entityContainer; }
/// <summary> /// Converts an entity set from SOM to metadata /// </summary> /// <param name="set">The SOM element to process</param> /// <param name="providerManifest">The provider manifest to be used for conversion</param> /// <param name="convertedItemCache">The item collection for currently existing metadata objects</param> /// <param name="newGlobalItems">The new GlobalItem objects that are created as a result of this conversion</param> /// <returns>The entity set object resulting from the convert</returns> private static EntitySet ConvertToEntitySet( Som.EntityContainerEntitySet set, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems) { var entitySet = new EntitySet( set.Name, set.DbSchema, set.Table, set.DefiningQuery, (EntityType)LoadSchemaElement( set.EntityType, providerManifest, convertedItemCache, newGlobalItems)); // Extract the optional Documentation if (set.Documentation != null) { entitySet.Documentation = ConvertToDocumentation(set.Documentation); } AddOtherContent(set, entitySet); return entitySet; }
protected override System.Data.Entity.Core.Common.DbCommandDefinition CreateDbCommandDefinition( System.Data.Entity.Core.Common.DbProviderManifest providerManifest, DbCommandTree commandTree) { if (commandTree == null) { throw new ArgumentNullException("commandTree"); } SqlGenerator generator = null; if (commandTree is DbQueryCommandTree) { generator = new SelectGenerator(); } else if (commandTree is DbInsertCommandTree) { generator = new InsertGenerator(); } else if (commandTree is DbUpdateCommandTree) { generator = new UpdateGenerator(); } else if (commandTree is DbDeleteCommandTree) { generator = new DeleteGenerator(); } else if (commandTree is DbFunctionCommandTree) { generator = new FunctionGenerator(); } string sql = generator.GenerateSQL(commandTree); EFMySqlCommand cmd = new EFMySqlCommand(); cmd.CommandText = sql; if (generator is FunctionGenerator) { cmd.CommandType = (generator as FunctionGenerator).CommandType; } SetExpectedTypes(commandTree, cmd); EdmFunction function = null; if (commandTree is DbFunctionCommandTree) { function = (commandTree as DbFunctionCommandTree).EdmFunction; } // Now make sure we populate the command's parameters from the CQT's parameters: foreach (KeyValuePair <string, TypeUsage> queryParameter in commandTree.Parameters) { DbParameter parameter = cmd.CreateParameter(); parameter.ParameterName = queryParameter.Key; parameter.Direction = ParameterDirection.Input; parameter.DbType = Metadata.GetDbType(queryParameter.Value); #if NET_45_OR_GREATER if (queryParameter.Value.EdmType is PrimitiveType && ((PrimitiveType)queryParameter.Value.EdmType).PrimitiveTypeKind == PrimitiveTypeKind.Geometry) { ((MySqlParameter)parameter).MySqlDbType = MySqlDbType.Geometry; } #endif FunctionParameter funcParam; if (function != null && function.Parameters.TryGetValue(queryParameter.Key, false, out funcParam)) { parameter.ParameterName = funcParam.Name; parameter.Direction = Metadata.ModeToDirection(funcParam.Mode); parameter.DbType = Metadata.GetDbType(funcParam.TypeUsage); } cmd.Parameters.Add(parameter); } // Now add parameters added as part of SQL gen foreach (DbParameter p in generator.Parameters) { cmd.Parameters.Add(p); } return(CreateCommandDefinition(cmd)); }
/// <summary> /// Converts an entity type from SOM to metadata /// /// This method should only build the internally contained and vertical part of the EntityType (keys, properties, and base types) but not /// sideways parts (NavigationProperties) that go between types or we risk trying to access and EntityTypes keys, from the referential constraint, /// before the base type, which has the keys, is setup yet. /// </summary> /// <param name="element">The SOM element to process</param> /// <param name="providerManifest">The provider manifest to be used for conversion</param> /// <param name="convertedItemCache">The item collection for currently existing metadata objects</param> /// <param name="newGlobalItems">The new GlobalItem objects that are created as a result of this conversion</param> /// <returns>The entity type object resulting from the convert</returns> private static EntityType ConvertToEntityType( Som.SchemaEntityType element, DbProviderManifest providerManifest, ConversionCache convertedItemCache, Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems) { string[] keyMembers = null; // Check if this type has keys if (element.DeclaredKeyProperties.Count != 0) { keyMembers = new string[element.DeclaredKeyProperties.Count]; for (var i = 0; i < keyMembers.Length; i++) { //Add the name of the key property to the list of //key properties keyMembers[i] = (element.DeclaredKeyProperties[i].Property.Name); } } var properties = new EdmProperty[element.Properties.Count]; var index = 0; foreach (var somProperty in element.Properties) { properties[index++] = ConvertToProperty( somProperty, providerManifest, convertedItemCache, newGlobalItems); } var entityType = new EntityType( element.Name, element.Namespace, GetDataSpace(providerManifest), keyMembers, properties); if (element.BaseType != null) { entityType.BaseType = (EdmType)(LoadSchemaElement( element.BaseType, providerManifest, convertedItemCache, newGlobalItems)); } // set the abstract and sealed type values for the entity type entityType.Abstract = element.IsAbstract; // Extract the optional Documentation if (element.Documentation != null) { entityType.Documentation = ConvertToDocumentation(element.Documentation); } AddOtherContent(element, entityType); newGlobalItems.Add(element, entityType); return entityType; }