コード例 #1
0
        public TestModelBuilder Association(
            string sourceEntity, EdmAssociationEndKind sourceEndKind,
            string targetEntity, EdmAssociationEndKind targetEndKind)
        {
            _model.AddAssociationSet(
                "AssociationSet",
                _model.AddAssociationType(
                    "Association",
                    _model.GetEntityType(sourceEntity), sourceEndKind,
                    _model.GetEntityType(targetEntity), targetEndKind));

            return this;
        }
コード例 #2
0
        public static EdmAssociationType AddAssociationType(
            this EdmModel model,
            string name,
            EdmEntityType sourceEntityType,
            EdmAssociationEndKind sourceAssociationEndKind,
            EdmEntityType targetEntityType,
            EdmAssociationEndKind targetAssociationEndKind)
        {
            //Contract.Requires(model != null);
            //Contract.Requires(!string.IsNullOrWhiteSpace(name));
            //Contract.Requires(sourceEntityType != null);
            //Contract.Requires(targetEntityType != null);
            Contract.Assert(model.Namespaces.Count == 1);

            var associationType = new EdmAssociationType().Initialize();

            associationType.Name = name;
            associationType.SourceEnd.Name = name + "_Source";
            associationType.SourceEnd.EntityType = sourceEntityType;
            associationType.SourceEnd.EndKind = sourceAssociationEndKind;
            associationType.TargetEnd.Name = name + "_Target";
            associationType.TargetEnd.EntityType = targetEntityType;
            associationType.TargetEnd.EndKind = targetAssociationEndKind;

            model.AddAssociationType(associationType);

            return associationType;
        }
コード例 #3
0
        public TestModelBuilder Association(string name,
            string sourceEntity, EdmAssociationEndKind sourceEndKind, string sourceNavigationProperty,
            string targetEntity, EdmAssociationEndKind targetEndKind, string targetNavigationProperty)
        {
            var sourceEntityType = _model.GetEntityType(sourceEntity);
            var targetEntityType = _model.GetEntityType(targetEntity);

            var association
                = _model.AddAssociationType(name, sourceEntityType, sourceEndKind, targetEntityType, targetEndKind);

            _model.AddAssociationSet(name + "Set", association);

            if (sourceNavigationProperty != null)
            {
                sourceEntityType.AddNavigationProperty(sourceNavigationProperty, association);
            }

            if (targetNavigationProperty != null)
            {
                targetEntityType.AddNavigationProperty(targetNavigationProperty, association);
            }

            return this;
        }
コード例 #4
0
 private static string GetXmlMultiplicity(EdmAssociationEndKind endKind)
 {
     switch (endKind)
     {
         case EdmAssociationEndKind.Many:
             return CsdlConstants.Value_EndMany;
         case EdmAssociationEndKind.Required:
             return CsdlConstants.Value_EndRequired;
         case EdmAssociationEndKind.Optional:
             return CsdlConstants.Value_EndOptional;
         default:
             Debug.Fail("Did you add a new EdmAssociationEndKind?");
             return string.Empty;
     }
 }