コード例 #1
0
        internal static void AddTerm(this IEdmModel model, IAnnotationConfiguration configuration, InstanceAnnotation annotation, string appliesTo)
        {
            Contract.Requires(model != null);
            Contract.Requires(configuration != null);
            Contract.Requires(annotation != null);
            Contract.Requires(!string.IsNullOrEmpty(appliesTo));

            // short-circuit if the term has already been added
            if (model.FindValueTerm(annotation.QualifiedName) != null)
            {
                return;
            }

            var typeRef  = annotation.IsComplex ? AddComplexTerm(model, annotation) : AddPrimitiveTerm(model, annotation);
            var termType = annotation.IsCollection ? new EdmCollectionTypeReference(new EdmCollectionType(typeRef)) : typeRef;

            AddTerm(model, configuration, termType, appliesTo);
        }
コード例 #2
0
        private static void AddTerm(IEdmModel model, IAnnotationConfiguration configuration, IEdmTypeReference termType, string appliesTo)
        {
            Contract.Requires(model != null);
            Contract.Requires(configuration != null);
            Contract.Requires(termType != null);
            Contract.Requires(!string.IsNullOrEmpty(appliesTo));

            // TODO: refactor this, when possible, to not use/rely on the following cast
            //
            // casting to EdmModel is not safe, but there is seemingly no other way to add
            // the term for the annotation to the model. this would be true even if we
            // subclass ODataModelBuilder or ODataConventionModelBuilder since GetEmdModel
            // returns IEdmModel. Completely reimplementing the internals of ODataModelBuilder
            // is not worth it at this point.
            var edmModel = (EdmModel)model;
            var term     = new EdmTerm(configuration.Namespace, configuration.Name, termType, appliesTo);

            edmModel.AddElement(term);
        }