예제 #1
0
        internal NewEntityDialog(ConceptualEntityModel model)
        {
            Debug.Assert(model != null, "model should not be null");
            _model = model;

            InitializeComponent();
            // Set the default font to VS shell font.
            var vsFont = VSHelpers.GetVSFont(Services.ServiceProvider);
            if (vsFont != null)
            {
                Font = vsFont;
            }
            keyPropertyCheckBox.Checked = true;

            propertyTypeComboBox.Items.AddRange(ModelHelper.AllPrimitiveTypesSorted(_model.Artifact.SchemaVersion));
            propertyTypeComboBox.SelectedItem = ModelConstants.Int32PropertyType;

            baseTypeComboBox.Items.Add(Resources.NoneDisplayValueUsedForUX);
            baseTypeComboBox.Items.AddRange(model.EntityTypes().ToArray());
            if (baseTypeComboBox.Items.Count > 0)
            {
                baseTypeComboBox.SelectedIndex = 0;
            }

            entityNameTextBox.Text = ModelHelper.GetUniqueNameWithNumber(
                typeof(EntityType), model, Model.Resources.Model_DefaultEntityTypeName);
            propertyNameTextBox.Text = Model.Resources.Model_IdPropertyName;
        }
        private void RecordInheritanceAndEntityTypeMappings(ConceptualEntityModel cem)
        {
            // ensure _cEntityTypeToEntityTypeIdentity has been constructed
            Debug.Assert(null != _cEntityTypeNameToEntityTypeIdentity, "Null _cEntityTypeToEntityTypeIdentity");

            // now loop over EntityTypes. For each EntityType that has a base
            // type, map each DatabaseObject in the EntityTypeIdentity which is the
            // child type's identity to all TablesAndViews in the base type (and to 
            // all TablesAndViews in its base-type and so on up the chain).
            //
            // Note: although the normal case is a mapping 1 DatabaseObject -> 1 DatabaseObject
            // it is possible for mappings to overlap e.g. consider C-Side type C1 
            // which maps to EntityTypeIdentity {T1, T2} with a base type C2 which maps to
            // EntityTypeIdentity {T3, T4) and C-side type C3 which maps to
            // EntityTypeIdentity {T2, T5} with base type C4 which maps to {T4, T6}
            // Then this map will contain mappings:
            //   T1 -> {T3, T4}
            //   T2 -> {T3, T4, T6}
            //   T5 -> {T4, T6}
            // In the above {T3, T4, T6} is not the identity of any given C-side
            // entity type. But it allows us to know that something which maps to 
            // T2 (amongst others), has a base type which maps to T6 (amongst others).
            //
            // Also record the DatabaseObject->EntityType mappings.
            foreach (var et in cem.EntityTypes())
            {
                // Note: etEntityTypeId below will be null for unmapped EntityTypes
                var etEntityTypeId = GetEntityTypeIdentityForEntityType(et);
                if (null != etEntityTypeId)
                {
                    // record DatabaseObject->EntityType mappings
                    foreach (var etTableOrView in etEntityTypeId.TablesAndViews)
                    {
                        AddDbObjToEntityTypeNameMap(etTableOrView, et);
                    }

                    // record inheritance mappings
                    foreach (var etTableOrView in etEntityTypeId.TablesAndViews)
                    {
                        AddDbObjToEntityTypeNameMap(etTableOrView, et);

                        // loop over all ancestor types (i.e. this EntityType's base-type
                        // and its base-type etc.)
                        var baseType = et as ConceptualEntityType;
                        Debug.Assert(baseType != null, "EntityType is not a ConceptualEntityType");

                        while ((baseType = baseType.BaseType.Target) != null)
                        {
                            var baseTypeEntityTypeId = GetEntityTypeIdentityForEntityType(baseType);
                            if (null != etEntityTypeId
                                && null != baseTypeEntityTypeId)
                            {
                                foreach (var baseTypeTableOrView in baseTypeEntityTypeId.TablesAndViews)
                                {
                                    AddTableOrViewToBaseTypeMappings(etTableOrView, baseTypeTableOrView);
                                }
                            }
                        }
                    }
                }
            }
        }
        private static EntityDesignNewFunctionImportResult ShowNewFunctionImportDialog(
            Function selectedSproc,
            string selectedSprocName,
            StorageEntityModel sModel,
            ConceptualEntityModel cModel,
            ConceptualEntityContainer cContainer,
            string dialogTitle,
            Object selectedObject)
        {
            using (var dialog = new NewFunctionImportDialog(
                selectedSproc,
                selectedSprocName,
                sModel.Functions(),
                cModel.ComplexTypes(),
                cModel.EntityTypes(),
                cContainer,
                selectedObject))
            {
                dialog.Text = dialogTitle;

                var dialogResult = dialog.ShowDialog();

                var result = new EntityDesignNewFunctionImportResult
                    {
                        DialogResult = dialogResult,
                        Function = dialog.Function,
                        FunctionName = dialog.FunctionImportName,
                        IsComposable = dialog.IsComposable,
                        ReturnType = dialog.ReturnType,
                        Schema = dialog.Schema
                    };

                return result;
            }
        }