public EFTableProvider(EFDataModelProvider dataModel, EntitySet entitySet, EntityType entityType,
            Type entityClrType, Type parentEntityClrType, Type rootEntityClrType, string name)
            : base(dataModel) {

            EntityType = entityClrType;
            Name = name;
            DataContextPropertyName = entitySet.Name;
            ParentEntityType = parentEntityClrType;
            RootEntityType = rootEntityClrType;

            var genericMethod = DataModel.ContextType.GetMethod("CreateQuery");
            CreateQueryMethod = genericMethod.MakeGenericMethod(EntityType);
            CreateQueryString = CreateEntitySqlQueryString(entitySet);

            var keyMembers = entityType.KeyMembers;

            // columns (entity properties)
            // note 1: keys are also available through es.ElementType.KeyMembers
            // note 2: this includes "nav properties", kind of fancy, two-way relationship objects
            var columns = new List<ColumnProvider>();
            foreach (EdmMember m in entityType.Members) {
                if (EFColumnProvider.IsSupportedEdmMemberType(m) && IsPublicProperty(entityClrType, m.Name)) {
                    EFColumnProvider entityMember = new EFColumnProvider(entityType, this, m, keyMembers.Contains(m));
                    columns.Add(entityMember);
                }
            }

            _roColumns = new ReadOnlyCollection<ColumnProvider>(columns);
        }
        public EdmTableProvider(EdmDataModelProvider dataModel, EntitySet entitySet, EntityType entityType, string name,
            bool isReadonly, bool supportPagingAndSorting)
            : base(dataModel)
        {
            _isReadonly = isReadonly;
            SupportPaging = supportPagingAndSorting;
            Name = name;
            DataContextPropertyName = entitySet.Name;
            EdmEntityType = entityType;

            var keyMembers = entityType.KeyMembers;

            // columns (entity properties)
            // note 1: keys are also available through es.ElementType.KeyMembers
            // note 2: this includes "nav properties", kind of fancy, two-way relationship objects
            var columns = new List<ColumnProvider>();
            foreach (EdmMember m in entityType.Members) {
                if (EdmColumnProvider.IsSupportedEdmMemberType(m)) {
                    var entityMember = new EdmColumnProvider(entityType, this, m, keyMembers.Contains(m), supportPagingAndSorting);
                    columns.Add(entityMember);
                }
            }

            _roColumns = new ReadOnlyCollection<ColumnProvider>(columns);
        }
 /// <summary>
 /// Construct a new Mapping Fragment object
 /// </summary>
 /// <param name="tableExtent"></param>
 /// <param name="typeMapping"></param>
 internal StorageMappingFragment(EntitySet tableExtent, StorageTypeMapping typeMapping, bool distinctFlag) {
     Debug.Assert(tableExtent != null, "Table should not be null when constructing a Mapping Fragment");
     Debug.Assert(typeMapping != null, "TypeMapping should not be null when constructing a Mapping Fragment");
     this.m_tableExtent = tableExtent;
     this.m_typeMapping = typeMapping;
     this.m_isSQueryDistinct = distinctFlag;
 }
示例#4
0
        // ObjectStateEntry will not be detached and creation will be handled from ObjectStateManager
        internal ObjectStateEntry(ObjectStateManager cache, EntitySet entitySet, EntityState state)
        {
            Debug.Assert(cache != null, "cache cannot be null.");

            _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;
        }
        public EntityRecordInfo(EntityType metadata, IEnumerable<EdmMember> memberInfo, EntityKey entityKey, EntitySet entitySet)
            : base(TypeUsage.Create(metadata), memberInfo)
        {
            //Contract.Requires(entityKey != null);
            //Contract.Requires(entitySet != null);

            _entityKey = entityKey;
            ValidateEntityType(entitySet);
        }
        private readonly List<RelProperty> m_relProperties; // list of relationship properties for which we have values

        #endregion

        #region constructors

        internal NewEntityBaseOp(OpType opType, TypeUsage type, bool scoped, EntitySet entitySet, List<RelProperty> relProperties)
            : base(opType, type)
        {
            Debug.Assert(scoped || entitySet == null, "entitySet cann't be set of constructor isn't scoped");
            Debug.Assert(relProperties != null, "expected non-null list of rel-properties");
            m_scoped = scoped;
            m_entitySet = entitySet;
            m_relProperties = relProperties;
        }
        /// <summary>
        /// Constructs processor based on the contents of a change node.
        /// </summary>
        /// <param name="table">Table for which changes are being processed.</param>
        internal TableChangeProcessor(EntitySet table)
        {
            EntityUtil.CheckArgumentNull(table, "table");

            m_table = table;

            // cache information about table key
            m_keyOrdinals = InitializeKeyOrdinals(table);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="memberInfo"></param>
        /// <param name="entityKey"></param>
        public EntityRecordInfo(EntityType metadata, IEnumerable<EdmMember> memberInfo, EntityKey entityKey, EntitySet entitySet)
            : base(TypeUsage.Create(metadata), memberInfo) {
            EntityUtil.CheckArgumentNull<EntityKey>(entityKey, "entityKey");
            EntityUtil.CheckArgumentNull(entitySet, "entitySet");

            _entityKey = entityKey;
            _entitySet = entitySet;
            ValidateEntityType(entitySet);
        }
        /// <summary>
        /// Constructs processor based on the contents of a change node.
        /// </summary>
        /// <param name="table">Table for which changes are being processed.</param>
        internal TableChangeProcessor(EntitySet table)
        {
            //Contract.Requires(table != null);

            m_table = table;

            // cache information about table key
            m_keyOrdinals = InitializeKeyOrdinals(table);
        }
        private readonly EntitySet[] m_entitySetMap; // optional dictionary that maps values to entitysets

        /// <summary>
        /// Simple constructor
        /// </summary>
        /// <param name="entitySetColumn">column map representing the entityset</param>
        /// <param name="entitySetMap">Map from value -> the appropriate entityset</param>
        /// <param name="keyColumns">list of key columns</param>
        internal DiscriminatedEntityIdentity(
            SimpleColumnMap entitySetColumn, EntitySet[] entitySetMap,
            SimpleColumnMap[] keyColumns)
            : base(keyColumns)
        {
            Debug.Assert(entitySetColumn != null, "Must specify a column map to identify the entity set");
            Debug.Assert(entitySetMap != null, "Must specify a dictionary to look up entitysets");
            m_entitySetColumn = entitySetColumn;
            m_entitySetMap = entitySetMap;
        }
 private DiscriminatorMap(DbPropertyExpression discriminator,
     List<KeyValuePair<object, EntityType>> typeMap,
     Dictionary<EdmProperty, DbExpression> propertyMap,
     Dictionary<Query.InternalTrees.RelProperty, DbExpression> relPropertyMap,
     EntitySet entitySet)
 {
     this.Discriminator = discriminator;
     this.TypeMap = typeMap.AsReadOnly();
     this.PropertyMap = propertyMap.ToList().AsReadOnly();
     this.RelPropertyMap = relPropertyMap.ToList().AsReadOnly();
     this.EntitySet = entitySet;
 }
示例#13
0
        /// <summary>
        /// Finds all markup associated with the given source.
        /// </summary>
        /// <param name="source">Source expression. Must not be null.</param>
        /// <param name="translator">Translator containing session information.</param>
        /// <param name="sourceTable">Table from which the exception was thrown (must not be null).</param>
        /// <returns>Markup.</returns>
        internal static ReadOnlyCollection<IEntityStateEntry> GetAllStateEntries(PropagatorResult source, UpdateTranslator translator,
            EntitySet sourceTable)
        {
            Debug.Assert(null != source);
            Debug.Assert(null != translator);
            Debug.Assert(null != sourceTable);

            SourceInterpreter interpreter = new SourceInterpreter(translator, sourceTable);
            interpreter.RetrieveResultMarkup(source);

            return new ReadOnlyCollection<IEntityStateEntry>(interpreter.m_stateEntries);
        }
 private DiscriminatorMap(
     DbPropertyExpression discriminator,
     List<KeyValuePair<object, EntityType>> typeMap,
     Dictionary<EdmProperty, DbExpression> propertyMap,
     Dictionary<RelProperty, DbExpression> relPropertyMap,
     EntitySet entitySet)
 {
     Discriminator = discriminator;
     TypeMap = typeMap.AsReadOnly();
     PropertyMap = propertyMap.ToList().AsReadOnly();
     RelPropertyMap = relPropertyMap.ToList().AsReadOnly();
     EntitySet = entitySet;
 }
        /// <summary>
        /// Creates a column map for the given reader and function mapping.
        /// </summary>
        internal static CollectionColumnMap CreateFunctionImportStructuralTypeColumnMap(
            DbDataReader storeDataReader, FunctionImportMappingNonComposable mapping, int resultSetIndex, EntitySet entitySet,
            StructuralType baseStructuralType)
        {
            var resultMapping = mapping.GetResultMapping(resultSetIndex);
            Debug.Assert(resultMapping != null);
            if (resultMapping.NormalizedEntityTypeMappings.Count == 0) // no explicit mapping; use default non-polymorphic reader
            {
                // if there is no mapping, create default mapping to root entity type or complex type
                Debug.Assert(!baseStructuralType.Abstract, "mapping loader must verify abstract types have explicit mapping");

                return CreateColumnMapFromReaderAndType(
                    storeDataReader, baseStructuralType, entitySet, resultMapping.ReturnTypeColumnsRenameMapping);
            }

            // the section below deals with the polymorphic entity type mapping for return type
            var baseEntityType = baseStructuralType as EntityType;
            Debug.Assert(null != baseEntityType, "We should have entity type here");

            // Generate column maps for all discriminators
            var discriminatorColumns = CreateDiscriminatorColumnMaps(storeDataReader, mapping, resultSetIndex);

            // Generate default maps for all mapped entity types
            var mappedEntityTypes = new HashSet<EntityType>(resultMapping.MappedEntityTypes);
            mappedEntityTypes.Add(baseEntityType); // make sure the base type is represented
            var typeChoices = new Dictionary<EntityType, TypedColumnMap>(mappedEntityTypes.Count);
            ColumnMap[] baseTypeColumnMaps = null;
            foreach (var entityType in mappedEntityTypes)
            {
                var propertyColumnMaps = GetColumnMapsForType(storeDataReader, entityType, resultMapping.ReturnTypeColumnsRenameMapping);
                var entityColumnMap = CreateEntityTypeElementColumnMap(
                    storeDataReader, entityType, entitySet, propertyColumnMaps, resultMapping.ReturnTypeColumnsRenameMapping);
                if (!entityType.Abstract)
                {
                    typeChoices.Add(entityType, entityColumnMap);
                }
                if (entityType == baseStructuralType)
                {
                    baseTypeColumnMaps = propertyColumnMaps;
                }
            }

            // NOTE: We don't have a null sentinel here, because the stored proc won't 
            //       return one anyway; we'll just presume the data's always there.
            var polymorphicMap = new MultipleDiscriminatorPolymorphicColumnMap(
                TypeUsage.Create(baseStructuralType), baseStructuralType.Name, baseTypeColumnMaps, discriminatorColumns, typeChoices,
                (object[] discriminatorValues) => mapping.Discriminate(discriminatorValues, resultSetIndex));
            CollectionColumnMap collection = new SimpleCollectionColumnMap(
                baseStructuralType.GetCollectionType().TypeUsage, baseStructuralType.Name, polymorphicMap, null, null);
            return collection;
        }
        internal EntityRecordInfo(DataRecordInfo info, EntityKey entityKey, EntitySet entitySet)
            : base(info)
        {
            _entityKey = entityKey;
#if DEBUG
            try
            {
                ValidateEntityType(entitySet);
            }
            catch
            {
                Debug.Assert(false, "should always be valid EntityType when internally constructed");
                throw;
            }
#endif
        }
        // Determines which column ordinals in the table are part of the key.
        private static int[] InitializeKeyOrdinals(EntitySet table)
        {
            EntityType tableType = table.ElementType;
            IList<EdmMember> keyMembers = tableType.KeyMembers;
            IBaseList<EdmMember> members = TypeHelpers.GetAllStructuralMembers(tableType);
            int[] keyOrdinals = new int[keyMembers.Count];

            for (int keyMemberIndex = 0; keyMemberIndex < keyMembers.Count; keyMemberIndex++)
            {
                EdmMember keyMember = keyMembers[keyMemberIndex];
                keyOrdinals[keyMemberIndex] = members.IndexOf(keyMember);

                Debug.Assert(keyOrdinals[keyMemberIndex] >= 0 && keyOrdinals[keyMemberIndex] < members.Count,
                    "an EntityType key member must also be a member of the entity type");
            }

            return keyOrdinals;
        }
示例#18
0
    public string GetTableCreateScript(EntitySet entitySet, string connectionString, string version)
    {
      MySqlProviderServices service = new MySqlProviderServices();

      if (!String.IsNullOrEmpty(version))
        service.serverVersion = new Version(version);
      else
      {
        using (var conn = new MySqlConnection(connectionString.Replace(@"""", "")))
        {
          conn.Open();                  
          var v = DBVersion.Parse(conn.ServerVersion.ToString());        
          service.serverVersion = new Version(v.Major + "." + v.Minor);
        }
      }
      if (service.serverVersion == null) service.serverVersion = new Version("5.5");
      return service.GetTableCreateScript(entitySet); 
    }
        internal EntityRecordInfo(EntityType metadata, EntityKey entityKey, EntitySet entitySet)
            : base(TypeUsage.Create(metadata))
        {
            //Contract.Requires(entityKey != null);

            _entityKey = entityKey;
#if DEBUG
            try
            {
                ValidateEntityType(entitySet);
            }
            catch
            {
                Debug.Assert(false, "should always be valid EntityType when internally constructed");
                throw;
            }
#endif
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="entityKey"></param>
        internal EntityRecordInfo(EntityType metadata, EntityKey entityKey, EntitySet entitySet)
            : base(TypeUsage.Create(metadata)) {
            EntityUtil.CheckArgumentNull<EntityKey>(entityKey, "entityKey");

            _entityKey = entityKey;
            _entitySet = entitySet;
#if DEBUG
            try
            {
                ValidateEntityType(entitySet);
            }
            catch
            {
                Debug.Assert(false, "should always be valid EntityType when internally constructed");
                throw;
            }
#endif
        }
        internal EntityDataSourceWrapperCollection(ObjectContext context, EntitySet entitySet, EntityType restrictedEntityType)
        {
            EntityDataSourceUtil.CheckArgumentNull(context, "context");
            EntityDataSourceUtil.CheckArgumentNull(entitySet, "entitySet");

            _context = context;
            _wrapperList = new List<EntityDataSourceWrapper>();

            // get handles on the relevant workspaces
            MetadataWorkspace csWorkspace = ((EntityConnection)context.Connection).GetMetadataWorkspace();
            MetadataWorkspace ocWorkspace = context.MetadataWorkspace;

            // if no restricted type is given, we assume the entity set element type is exposed
            EntityType entityType = restrictedEntityType ?? entitySet.ElementType;
            _clrEntityType = EntityDataSourceUtil.GetClrType(ocWorkspace, entityType);
            
            // if no restricted type is given and the set is polymorphic, make the collection readonly
            if (null == restrictedEntityType &&
                1 < EntityDataSourceUtil.GetTypeAndSubtypesOf(entityType, csWorkspace.GetItemCollection(DataSpace.CSpace), true).Count())
            {
                _isReadOnly = true;
            }

            // gather the properties
            ReadOnlyCollection<EntityDataSourceColumn> columns = EntityDataSourceUtil.GetNamedColumns(csWorkspace, ocWorkspace, entitySet, entityType);
            List<PropertyDescriptor> visiblePropertyDescriptors = new List<PropertyDescriptor>(columns.Count);
            List<EntityDataSourceWrapperPropertyDescriptor> propertyDescriptors = new List<EntityDataSourceWrapperPropertyDescriptor>(columns.Count);
            foreach (EntityDataSourceColumn column in columns)
            {
                var descriptor = new EntityDataSourceWrapperPropertyDescriptor(this, column);
                propertyDescriptors.Add(descriptor);

                // if the descriptor does not have a dependent, it is exposed to the user
                if (!descriptor.Column.IsHidden)
                {
                    visiblePropertyDescriptors.Add(descriptor);
                }
            }

            _visiblePropertyDescriptors = new PropertyDescriptorCollection(visiblePropertyDescriptors.ToArray(), true);
            AllPropertyDescriptors = propertyDescriptors.AsReadOnly();
        }
        // effects: Creates a foreign key constraint of the form:
        // <i_childTable, i_childColumns> --> <i_parentTable, i_childColumns>
        // i_fkeySet is the name of the constraint
        internal ForeignConstraint(AssociationSet i_fkeySet, EntitySet i_parentTable, EntitySet i_childTable,
                                   ReadOnlyMetadataCollection<EdmProperty> i_parentColumns, ReadOnlyMetadataCollection<EdmProperty> i_childColumns)
        {
            m_fKeySet = i_fkeySet;
            m_parentTable = i_parentTable;
            m_childTable = i_childTable;
            m_childColumns = new List<MemberPath>();
            // Create parent and child paths using the table names
            foreach (EdmProperty property in i_childColumns)
            {
                MemberPath path = new MemberPath(m_childTable, property);
                m_childColumns.Add(path);
            }

            m_parentColumns = new List<MemberPath>();
            foreach (EdmProperty property in i_parentColumns)
            {
                MemberPath path = new MemberPath(m_parentTable, property);
                m_parentColumns.Add(path);
            }
        }
        // requires: entitySet must not be null
        // Yields all referenced association set ends in this mapping.
        private static IEnumerable<AssociationSetEnd> GetReferencedAssociationSetEnds(
            EntitySet entitySet, EntityType entityType, IEnumerable<StorageModificationFunctionParameterBinding> parameterBindings)
        {
            var ends = new HashSet<AssociationSetEnd>();
            if (null != entitySet
                && null != entityType)
            {
                foreach (var parameterBinding in parameterBindings)
                {
                    var end = parameterBinding.MemberPath.AssociationSetEnd;
                    if (null != end)
                    {
                        ends.Add(end);
                    }
                }

                // If there is a referential constraint, it counts as an implicit mapping of
                // the association set
                foreach (var assocationSet in MetadataHelper.GetAssociationsForEntitySet(entitySet))
                {
                    var constraints = assocationSet.ElementType.ReferentialConstraints;
                    if (null != constraints)
                    {
                        foreach (var constraint in constraints)
                        {
                            if ((assocationSet.AssociationSetEnds[constraint.ToRole.Name].EntitySet == entitySet)
                                &&
                                (constraint.ToRole.GetEntityType().IsAssignableFrom(entityType)))
                            {
                                ends.Add(assocationSet.AssociationSetEnds[constraint.FromRole.Name]);
                            }
                        }
                    }
                }
            }
            return ends;
        }
        /// <summary>
        /// Build the collectionColumnMap from a store datareader, a type and an entitySet.
        /// </summary>
        /// <param name="storeDataReader"></param>
        /// <param name="edmType"></param>
        /// <param name="entitySet"></param>
        /// <returns></returns>
        internal static CollectionColumnMap CreateColumnMapFromReaderAndType(DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet, Dictionary<string, FunctionImportReturnTypeStructuralTypeColumnRenameMapping> renameList)
        {
            Debug.Assert(Helper.IsEntityType(edmType) || null == entitySet, "The specified non-null EntitySet is incompatible with the EDM type specified.");

            // Next, build the ColumnMap directly from the edmType and entitySet provided.
            ColumnMap[] propertyColumnMaps = GetColumnMapsForType(storeDataReader, edmType, renameList);
            ColumnMap elementColumnMap = null;

            // NOTE: We don't have a null sentinel here, because the stored proc won't 
            //       return one anyway; we'll just presume the data's always there.
            if (Helper.IsRowType(edmType))
            {
                elementColumnMap = new RecordColumnMap(TypeUsage.Create(edmType), edmType.Name, propertyColumnMaps, null);
            }
            else if (Helper.IsComplexType(edmType))
            {
                elementColumnMap = new ComplexTypeColumnMap(TypeUsage.Create(edmType), edmType.Name, propertyColumnMaps, null);
            }
            else if (Helper.IsScalarType(edmType))
            {
                if (storeDataReader.FieldCount != 1)
                {
                    throw EntityUtil.CommandExecutionDataReaderFieldCountForScalarType();
                }
                elementColumnMap = new ScalarColumnMap(TypeUsage.Create(edmType), edmType.Name, 0, 0);
            }
            else if (Helper.IsEntityType(edmType))
            {
                elementColumnMap = CreateEntityTypeElementColumnMap(storeDataReader, edmType, entitySet, propertyColumnMaps, null/*renameList*/);
            }
            else
            {
                Debug.Assert(false, "unexpected edmType?");
            }
            CollectionColumnMap collection = new SimpleCollectionColumnMap(edmType.GetCollectionType().TypeUsage, edmType.Name, elementColumnMap, null, null);
            return collection;
        }
        /// <summary>
        ///     Creates a new WrappedEntityKey instance.
        /// </summary>
        /// <param name = "entitySet">The entity set that the key belongs to.</param>
        /// <param name = "entitySetName">The fully qualified name of the given entity set.</param>
        /// <param name = "keyValues">The key values, which may be null or contain null values.</param>
        /// <param name = "keyValuesParamName">The name of the parameter passed for keyValue by the user, which is used when throwing exceptions.</param>
        public WrappedEntityKey(
            EntitySet entitySet, string entitySetName, object[] keyValues, string keyValuesParamName)
        {
            // Treat a null array as an array with a single null value since the common case for this is Find(null)
            if (keyValues == null)
            {
                keyValues = new object[] { null };
            }

            var keyNames = entitySet.ElementType.KeyMembers.Select(m => m.Name).ToList();
            if (keyNames.Count
                != keyValues.Length)
            {
                throw new ArgumentException(Strings.DbSet_WrongNumberOfKeyValuesPassed, keyValuesParamName);
            }

            _keyValuePairs = keyNames.Zip(keyValues, (name, value) => new KeyValuePair<string, object>(name, value));

            // Can only create a real EntityKey if all key values are null.
            if (keyValues.All(v => v != null))
            {
                _key = new EntityKey(entitySetName, KeyValuePairs);
            }
        }
 protected static MemberAttributes GetEntitySetPropertyAccessibility(EntitySet item)
 {
     return GetAccessibilityValue(item, XmlConstants.GetterAccess);
 }
示例#27
0
    internal string GetTableCreateScript(EntitySet entitySet)
    {
      EntityType e = entitySet.ElementType;
      _guidIdentityColumns = new List<string>();

      string typeName = null;
      if (_pluralizedNames.ContainsKey(e.Name))
      {
        typeName = _pluralizedNames[e.Name];
      }
      else
      {
        _pluralizedNames.Add(e.Name, 
          (string)entitySet.MetadataProperties["Table"].Value == null ? 
          e.Name : (string)entitySet.MetadataProperties["Table"].Value);
        typeName = _pluralizedNames[e.Name];
      }

      StringBuilder sql = new StringBuilder("CREATE TABLE ");
      sql.AppendFormat("`{0}`(", typeName );
      string delimiter = "";
      foreach (EdmProperty c in e.Properties)
      {
        sql.AppendFormat("{0}{1}\t`{2}` {3}{4}", delimiter, Environment.NewLine, c.Name,
            GetColumnType(c.TypeUsage), GetFacetString(c));
        delimiter = ", ";
      }
      sql.AppendLine(");");
      sql.AppendLine();
      if (e.KeyMembers.Count > 0)
      {
        sql.Append(String.Format(
            "ALTER TABLE `{0}` ADD PRIMARY KEY (", typeName ));
        delimiter = "";
        foreach (EdmMember m in e.KeyMembers)
        {
          sql.AppendFormat("{0}{1}", delimiter, m.Name);
          delimiter = ", ";
        }
        sql.AppendLine(");");
        sql.AppendLine();
      }
      if (_guidIdentityColumns.Count > 0)
      {
        sql.AppendLine("DELIMITER ||");
        sql.AppendLine(string.Format("CREATE TRIGGER `{0}` BEFORE INSERT ON `{1}`", typeName + "_IdentityTgr", typeName));
        sql.AppendLine("\tFOR EACH ROW BEGIN");
        foreach (string guidColumn in _guidIdentityColumns)
        {
          if (e.KeyMembers.Contains(guidColumn))
          {
            sql.AppendLine(string.Format("\t\tDROP TEMPORARY TABLE IF EXISTS tmpIdentity_{0};", typeName));
            sql.AppendLine(string.Format("\t\tCREATE TEMPORARY TABLE tmpIdentity_{0} (guid CHAR(36))ENGINE=MEMORY;", typeName));
            sql.AppendLine(string.Format("\t\tSET @var_{0} = UUID();", guidColumn));
            sql.AppendLine(string.Format("\t\tINSERT INTO tmpIdentity_{0} VALUES(@var_{1});", typeName, guidColumn));
            sql.AppendLine(string.Format("\t\tSET new.{0} = @var_{0};", guidColumn));
          }
          else
            sql.AppendLine(string.Format("\t\tSET new.{0} = UUID();", guidColumn));
        }
        sql.AppendLine("\tEND ||");
        sql.AppendLine("DELIMITER ;");
      }
      sql.AppendLine();
      return sql.ToString();
    }
示例#28
0
 /// <summary>
 /// Gets sub item of the specified EntitySet instance by the name 
 /// </summary>
 /// <param name="entitySet">The EntitySet instance</param>
 /// <param name="name">The name of sub item</param>
 /// <returns>sub item object if one is found; null otherwise</returns>
 private static ODataUriItem GetItem(EntitySet entitySet, string name)
 {
     if (name.Equals("$count", StringComparison.Ordinal))
     {
         return new ODataUriItem(entitySet, UriType.URI15);
     }
     else
     {
         return null;
     }
 }
 private static bool CheckLOJCycle(EntitySet child, EntitySet parent, Dictionary<EntitySet, EntitySet> nestedExtents)
 {
     do
     {
         if (EqualityComparer<EntitySet>.Default.Equals(parent, child))
         {
             return true;
         }
     }
     while (nestedExtents.TryGetValue(parent, out parent));
     return false;
 }
 private static IEnumerable<EntitySet> GetFKOverPKDependents(EntitySet principal)
 {
     foreach (var pkFkInfo in principal.ForeignKeyPrincipals)
     {
         // If principal has a related extent with FK pointing to principal and the FK is based on PK columns of the related extent,
         // then add it.
         var pkColumns = pkFkInfo.Item2.ToRole.GetEntityType().KeyMembers;
         var fkColumns = pkFkInfo.Item2.ToProperties;
         if (pkColumns.Count
             == fkColumns.Count)
         {
             // Compare PK to FK columns, order is important (otherwise it's not an FK over PK).
             var i = 0;
             for (; i < pkColumns.Count && pkColumns[i].EdmEquals(fkColumns[i]); ++i)
             {
                 ;
             }
             if (i == pkColumns.Count)
             {
                 yield return
                     pkFkInfo.Item1.AssociationSetEnds.Where(ase => ase.Name == pkFkInfo.Item2.ToRole.Name).Single().EntitySet;
             }
         }
     }
 }