private static Property CreateConceptualProperty(ConceptualEntityType parentEntity, string name, string type, InsertPropertyPosition insertPosition) { var property = new ConceptualProperty(parentEntity, null, insertPosition); property.LocalName.Value = name; property.ChangePropertyType(type); return(property); }
// add one PropagateConceptualSGPToStorageProperty for each StorageProperty mapped to this ConceptualProperty internal static void AddRule(CommandProcessorContext cpc, ConceptualProperty cProp, bool propagateNoneSGP) { if (null != cProp) { foreach (var sProp in MappedStorageProperties(cProp)) { IIntegrityCheck check = new PropagateStoreGeneratedPatternToStorageModel(cpc, sProp, propagateNoneSGP); cpc.AddIntegrityCheck(check); } } }
protected override void ProcessPreReqCommands() { if (_property == null) { var prereq = GetPreReqCommand(CreatePropertyCommand.PrereqId) as CreatePropertyCommand; Debug.Assert(null != prereq, "Pre-req CreatePropertyCommand is not present for PrereqId " + CreatePropertyCommand.PrereqId); if (null != prereq) { var prop = prereq.CreatedProperty; Debug.Assert(null != prop, "Pre-req Command returned null Property"); if (null != prop) { _property = prop as ConceptualProperty; Debug.Assert( null != _property, "Pre-req Command returned Property of type " + prop.GetType().FullName + ". Should be ConceptualProperty"); } } } }
/// <summary> /// returns list of StorageProperties mapped to a ConceptualProperty via an EntitySetMapping /// or an EntityTypeMapping /// </summary> /// <param name="cProp"></param> /// <returns></returns> private static IEnumerable <StorageProperty> MappedStorageProperties(ConceptualProperty cProp) { Debug.Assert(null != cProp, "null ConceptualProperty"); if (null != cProp) { // loop over ConceptualProperties mapped to this ConceptualProperty foreach (var sp in cProp.GetAntiDependenciesOfType <ScalarProperty>()) { // only use ScalarProperty elements inside an EntitySetMapping or EntityTypeMapping // (MappingFragment is only used by those types of mappings) if (null != sp.GetParentOfType(typeof(MappingFragment))) { var sProp = sp.ColumnName.Target as StorageProperty; if (null != sProp) { yield return(sProp); } } } } }
private static SortedListAllowDupes <DatabaseColumn> GetMappedColumnsForConceptualProperty(ConceptualProperty property) { var columns = new SortedListAllowDupes <DatabaseColumn>(new DatabaseColumnComparer()); if (property != null) { foreach (var sp in property.GetAntiDependenciesOfType <ScalarProperty>()) { // only want scalar props for a mapping fragment, not for an association set mapping if (sp.Parent is MappingFragment) { if (sp.ColumnName.Target == null) { Debug.Fail("Null target for " + sp.ToPrettyString()); } else { // in the situation where property is in multiple EntityTypeMappings (an inheritance // hierarchy) there can be multiple ScalarProperty anti-dependencies of property // (one for each EntityTypeMapping) all of which map to the same DatabaseColumn - // in this case only insert the first of these var dbCol = DatabaseColumn.CreateFromProperty(sp.ColumnName.Target); if (!columns.Contains(dbCol)) { columns.Add(dbCol); } } } } } return(columns); }
protected override void InvokeInternal(CommandProcessorContext cpc) { // safety check, this should never be hit Debug.Assert(ParentComplexType != null, "InvokeInternal is called when ParentComplexType is null."); if (ParentComplexType == null) { throw new InvalidOperationException("InvokeInternal is called when ParentComplexType is null"); } Debug.Assert(!(Type == null && ComplexType == null), "InvokeInternal is called when Type or ComplexType is null."); if (Type == null && ComplexType == null) { throw new InvalidOperationException("InvokeInternal is called when Type and ComplexType is null"); } // check for uniqueness string msg; if (!ModelHelper.ValidateComplexTypePropertyName(ParentComplexType, Name, true, out msg)) { throw new CommandValidationFailedException(msg); } // check for ComplexType circular definition if (ComplexType != null) { if (ModelHelper.ContainsCircularComplexTypeDefinition(ParentComplexType, ComplexType)) { throw new CommandValidationFailedException( String.Format( CultureInfo.CurrentCulture, Resources.Error_CircularComplexTypeDefinitionOnAdd, ComplexType.LocalName.Value)); } } // create the property Property property = null; if (Type != null) { var conceptualProperty = new ConceptualProperty(ParentComplexType, null); conceptualProperty.ChangePropertyType(Type); property = conceptualProperty; } else { var complexProperty = new ComplexConceptualProperty(ParentComplexType, null); complexProperty.ComplexType.SetRefName(ComplexType); property = complexProperty; } Debug.Assert(property != null, "property should not be null"); if (property == null) { throw new ItemCreationFailureException(); } // set the name and add to the parent entity property.LocalName.Value = Name; ParentComplexType.AddProperty(property); // set other attributes of the property if (Nullable != null) { property.Nullable.Value = (Nullable.Value ? BoolOrNone.TrueValue : BoolOrNone.FalseValue); } XmlModelHelper.NormalizeAndResolve(property); _createdProperty = property; }