/// <summary> /// Override the default method, adding generation of root queries that call designated service operations /// </summary> /// <param name="entityModelSchema">Entity Model Schema</param> /// <param name="queryTypeLibrary">Query Type Library</param> protected override void BuildRootQueriesAndTypes(EntityModelSchema entityModelSchema, QueryTypeLibrary queryTypeLibrary) { base.BuildRootQueriesAndTypes(entityModelSchema, queryTypeLibrary); // For each service operation marked as root, add a root query that calls the operation var rootServiceOperationQueries = new List <QueryExpression>(); foreach (var serviceOperation in entityModelSchema.Functions.Where(f => f.Annotations.OfType <FunctionBodyAnnotation>().Any(a => a.IsRoot))) { QueryExpression bodyExpression = serviceOperation.Annotations.OfType <FunctionBodyAnnotation>().Single().FunctionBody; ExceptionUtilities.CheckObjectNotNull(bodyExpression, "Root level function has null body expression"); QueryType rootQueryType = queryTypeLibrary.GetDefaultQueryType(serviceOperation.ReturnType); var rootQuery = new QueryCustomFunctionCallExpression(rootQueryType, serviceOperation, bodyExpression, true, false); rootServiceOperationQueries.Add(rootQuery); QueryStructuralType structuralType = rootQueryType as QueryStructuralType; if (structuralType == null) { QueryCollectionType collectionType = rootQueryType as QueryCollectionType; if (collectionType != null) { structuralType = collectionType.ElementType as QueryStructuralType; } } ExceptionUtilities.CheckObjectNotNull(structuralType, "Root level service op query must return structural type"); this.RootDataTypes.Add(serviceOperation.Name, structuralType); } this.RootQueries = this.RootQueries.Concat(rootServiceOperationQueries); }
/// <summary> /// Creates structural data services for the entity model. /// </summary> /// <param name="modelSchema">Entity model schema.</param> /// <returns> /// An <see cref="IEntityModelConceptualDataServices"/>. /// </returns> public IEntityModelConceptualDataServices CreateConceptualDataServices(EntityModelSchema modelSchema) { ExceptionUtilities.CheckArgumentNotNull(modelSchema, "modelSchema"); ExceptionUtilities.CheckAllRequiredDependencies(this); try { this.structuralGenerators = new ConceptualDataServices(); foreach (ComplexType complexType in modelSchema.ComplexTypes) { this.GetOrCreateAndRegisterStructuralDataGeneratorForComplexType(complexType); } foreach (EntityContainer entityContainer in modelSchema.EntityContainers) { foreach (var entitySet in entityContainer.EntitySets) { this.CreateAndRegisterStructuralDataGeneratorsForEntitySet(entitySet); } } return(this.structuralGenerators); } finally { this.structuralGenerators = null; } }
private static void ResolveDataGenerationHints(EntityModelSchema model, DependencyInjectionContainer container) { var entityModelHintsResolver = container.Resolve <IEntityModelDataGenerationHintsResolver>(); var primitiveResolver = container.Resolve <IPrimitiveDataTypeToDataGenerationHintsResolver>(); entityModelHintsResolver.ResolveDataGenerationHints(model, primitiveResolver); }
/// <summary> /// Improve the model if goals not yet met /// </summary> /// <param name="model">model to improve</param> public override void Improve(EntityModelSchema model) { while (model.EntityTypes.Count() < this.MinNumberOfEntities) { model.Add(new EntityType()); } }
/// <summary> /// Generates POCO entities based on the supplied model /// </summary> /// <param name="model">Model to generate classes from</param> /// <returns>Generated code files</returns> public IEnumerable <FileContents <string> > GenerateEntityClasses(EntityModelSchema model) { ExceptionUtilities.CheckArgumentNotNull(model, "model"); PocoAnnotator.Annotate(model, this.PocoOption); List <FileContents <string> > results = new List <FileContents <string> >(); foreach (var ns in model.EntityTypes.Select(e => e.NamespaceName).Concat(model.EnumTypes.Select(e => e.NamespaceName)).Concat(model.ComplexTypes.Select(e => e.NamespaceName)).Distinct()) { var codeUnit = new CodeCompileUnit(); CodeNamespace codeNamespace = codeUnit.AddNamespace(ns); codeNamespace.ImportNamespace("System.Collections.Generic"); foreach (var type in model.ComplexTypes.Where(e => e.NamespaceName == ns)) { codeNamespace.Types.Add(this.BuildType(type)); } foreach (var type in model.EntityTypes.Where(e => e.NamespaceName == ns)) { codeNamespace.Types.Add(this.BuildType(type)); } foreach (var type in model.EnumTypes.Where(e => e.NamespaceName == ns)) { codeNamespace.Types.Add(this.BuildType(type)); } string code = this.GenerateCodeFromCompileUnit(codeUnit); results.Add(new FileContents <string>(ns + this.language.FileExtension, code)); } return(results); }
/// <summary> /// Parses a single csdl/ssdl file. /// </summary> /// <param name="model">the entity model schema which the csdl/ssdl file parses to</param> /// <param name="schemaElement">the top level schema element in the csdl/ssdl file</param> protected virtual void ParseSingleXsdl(EntityModelSchema model, XElement schemaElement) { this.AssertXsdlElement(schemaElement, "Schema"); this.SetupNamespaceAndAliases(schemaElement); foreach (var entityContainerElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EntityContainer"))) { model.Add(this.ParseEntityContainer(entityContainerElement)); } foreach (var entityTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EntityType"))) { model.Add(this.ParseEntityType(entityTypeElement)); } foreach (var associationTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "Association"))) { model.Add(this.ParseAssociation(associationTypeElement)); } foreach (var functionElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "Function"))) { model.Add(this.ParseFunction(functionElement)); } }
/// <summary> /// Generates a query resolver to resolve entity sets to IQueryable /// </summary> /// <param name="model">The conceptual schema for the workspace</param> /// <returns>a Query resolver to resolver entity sets to IQueryable</returns> public override IODataQueryProvider CreateQueryProvider(EntityModelSchema model) { var queryProvider = new ClrBasedQueryProvider(this.Workspace.ObjectLayerAssembly, model, this.Evaluator, this.Repository); queryProvider.IsNullPropagationRequired = NullPropagationRequired; return(queryProvider); }
private void AddIncrementIntegerPropertyActions(EntityModelSchema model, EntitySet entitySet, string propertyName) { var entityType = entitySet.EntityType; model.Add( new Function(entityType.NamespaceName, "ReturnBindingEntity" + entityType.Name) { ReturnType = DataTypes.EntityType.WithDefinition(entityType), Parameters = { new FunctionParameter("bindingEntity", DataTypes.EntityType.WithDefinition(entityType)), }, Annotations = { new ServiceOperationAnnotation() { IsAction = true }, new IncrementIntegerPropertyValueActionAnnotation() { IntegerProperty = propertyName } } }); }
/// <summary> /// Performs the fixup for all items that have Name and Namespace. /// </summary> /// <param name="model">Model to perform fixup on.</param> public void Fixup(EntityModelSchema model) { foreach (INamedItem item in this.GetAllNamedItems(model)) { this.FixupNamedItem(item); } }
/// <summary> /// Improve the model if goal not yet met /// </summary> /// <param name="model">Model to improve</param> public override void Improve(EntityModelSchema model) { foreach (var et in model.EntityTypes) { var existingComplexProperties = et.Properties.Where(p => p.PropertyType is ComplexDataType).ToList(); if (existingComplexProperties.Count >= this.MinNumberOfComplexPropertiesPerEntity) { continue; } int numOfComplexPropertiesPerEntity = this.MinNumberOfComplexPropertiesPerEntity; if (this.RandomNumberGenerator != null) { numOfComplexPropertiesPerEntity = this.RandomNumberGenerator.NextFromRange(this.MinNumberOfComplexPropertiesPerEntity, this.MaxNumberOfComplexPropertiesPerEntity); } int remaining = numOfComplexPropertiesPerEntity - existingComplexProperties.Count; for (int i = 0; i < remaining; ++i) { et.Properties.Add(new MemberProperty() { PropertyType = DataTypes.ComplexType, }); } } }
/// <summary> /// Remove concurrency tokens defined on complex types and properties /// </summary> /// <param name="model">The model to fix up</param> public void Fixup(EntityModelSchema model) { foreach (var ct in model.ComplexTypes) { foreach (var property in ct.Properties) { // ToList is to avoid modifying the collection during enumeration foreach (var annotation in property.Annotations.OfType <ConcurrencyTokenAnnotation>().ToList()) { property.Annotations.Remove(annotation); } } } foreach (var et in model.EntityTypes) { foreach (var property in et.AllProperties.Where(p => p.PropertyType is ComplexDataType)) { // ToList is to avoid modifying the collection during enumeration foreach (var annotation in property.Annotations.OfType <ConcurrencyTokenAnnotation>().ToList()) { property.Annotations.Remove(annotation); } } } }
/// <summary> /// Generates an assembly that contains the object layer types for the given EntityModelSchema /// </summary> /// <param name="workspace">test workspace under construction</param> /// <param name="schema">The schema under test</param> /// <returns>An assembly that contains the object layer types for the given EntityModelSchema</returns> private Assembly GenerateObjectLayer(ODataTestWorkspace workspace, EntityModelSchema schema) { CodeCompileUnit objectLayerCompileUnit = new CodeCompileUnit(); this.ObjectLayerCodeGenerator.GenerateObjectLayer(objectLayerCompileUnit, schema); string objectLayerCode; using (var writer = new StringWriter(CultureInfo.InvariantCulture)) { this.Language.CreateCodeGenerator().GenerateCodeFromCompileUnit(objectLayerCompileUnit, writer, null); objectLayerCode = writer.ToString(); } string outputFilePath = Guid.NewGuid().ToString(); #if SILVERLIGHT outputFilePath = String.Format("{0}Assembly.dll", outputFilePath); return(typeof(DefaultNamespace.Phone).Assembly); #else outputFilePath = outputFilePath + ".dll"; this.Language.CompileAssemblyFromSource(outputFilePath, new[] { objectLayerCode }, referenceAssemblies); var assembly = AssemblyHelpers.LoadAssembly(outputFilePath, referenceAssemblies); return(assembly); #endif }
/// <summary> /// Improve the model if goal not yet met /// </summary> /// <param name="model">Model to improve</param> public override void Improve(EntityModelSchema model) { foreach (var et in model.EntityTypes .Where(c => c.BaseType == null) .Where(c => c.AllKeyProperties.Count() < this.MinNumberOfKeysPerEntities)) { int numOfKeyPropertiesNeeded = this.MinNumberOfKeysPerEntities; if (this.MinNumberOfKeysPerEntities != this.MaxNumberOfKeysPerEntities) { numOfKeyPropertiesNeeded = this.Random.NextFromRange(this.MinNumberOfKeysPerEntities, this.MaxNumberOfKeysPerEntities); } // Consume the existing properties... foreach (MemberProperty mp in et.Properties.Where(p => p.IsPrimaryKey == false).SkipWhile(q => q.PropertyType is ComplexDataType)) { if (et.AllKeyProperties.Count() < numOfKeyPropertiesNeeded) { mp.IsPrimaryKey = true; } else { break; } } // Create new properties and make them key... while (et.AllKeyProperties.Count() < numOfKeyPropertiesNeeded) { et.Properties.Add(new MemberProperty() { IsPrimaryKey = true }); } } }
/// <summary> /// Adds the EntitySet information to an action or validates that it has an entitySet Path /// </summary> /// <param name="model">The model to fix up</param> public void Fixup(EntityModelSchema model) { foreach (Function f in model.Functions.Where(f => f.IsAction() && f.ReturnType != null)) { var serviceOperationAnnotation = f.Annotations.OfType <ServiceOperationAnnotation>().Single(); // If someone has set the entitySetPath or the entitySet name then we don't need to update anything if (serviceOperationAnnotation.EntitySetPath != null || serviceOperationAnnotation.EntitySetName != null) { continue; } EntityDataType entityDataType = f.ReturnType as EntityDataType; var collectionDataType = f.ReturnType as CollectionDataType; if (collectionDataType != null) { entityDataType = collectionDataType.ElementDataType as EntityDataType; } if (entityDataType != null) { var possibleMatch = model.EntityContainers.Single().EntitySets.Where(es => entityDataType.Definition.IsKindOf(es.EntityType)).ToList(); ExceptionUtilities.Assert(possibleMatch.Count == 1, string.Format(CultureInfo.InvariantCulture, "Cannot resolve function '{0}' to one EntitySet, possible matches were '{1}'", f.Name, string.Join(",", possibleMatch.Select(es => es.Name)))); serviceOperationAnnotation.EntitySetName = possibleMatch.Single().Name; } } }
private Dictionary <string, IList <object> > GroupModelItemsIntoNamespaces(EntityModelSchema model) { var namespace2Items = new Dictionary <string, IList <object> >(); this.GroupIntoNamespaces(model.EntityTypes.Cast <INamedItem>(), namespace2Items); this.GroupIntoNamespaces(model.ComplexTypes.Cast <INamedItem>(), namespace2Items); this.GroupIntoNamespaces(model.Associations.Cast <INamedItem>(), namespace2Items); this.GroupIntoNamespaces(model.Functions.Cast <INamedItem>(), namespace2Items); this.GroupIntoNamespaces(model.EnumTypes.Cast <INamedItem>(), namespace2Items); string containerNamespace = this.ContainerDefaultNamespace; if (namespace2Items.Keys.Count > 0) { containerNamespace = namespace2Items.Keys.First(); } else { namespace2Items[containerNamespace] = new List <object>(); } foreach (EntityContainer container in model.EntityContainers) { namespace2Items[containerNamespace].Add(container); } return(namespace2Items); }
/// <summary> /// Creates an <see cref="AssociationType"/> between the <paramref name="from"/> and <paramref name="to"/> /// entity types. It uses computed names for the association and its ends. /// </summary> /// <param name="from">The entity type the association starts on.</param> /// <param name="to">The entity type the association goes to.</param> /// <param name="isSingletonRelationship">true if the navigation property is of singleton cardinality; false for a cardinality many. Default is false.</param> /// <returns>A new <see cref="AssociationType"/> between the <paramref name="from"/> and <paramref name="to"/> entity types.</returns> public static AssociationType AssociationType(this EntityModelSchema model, EntityType from, EntityType to, bool isSingletonRelationship) { ExceptionUtilities.CheckArgumentNotNull(model, "model"); ExceptionUtilities.CheckArgumentNotNull(from, "from"); ExceptionUtilities.CheckArgumentNotNull(to, "to"); string associationTypeName = from.Name + "_" + to.Name; int index = 0; while (model.Associations.Where(a => a.Name == associationTypeName).Count() > 0) { index++; associationTypeName = from.Name + "_" + to.Name + index; } // create the association type AssociationType associationType = new AssociationType(associationTypeName) { new AssociationEnd("From" + from.Name, from, EndMultiplicity.ZeroOne), new AssociationEnd("To" + to.Name, to, isSingletonRelationship ? EndMultiplicity.One : EndMultiplicity.Many), }; model.Add(associationType); return(associationType); }
private bool NeedsAnnotationNamespace(EntityModelSchema schema) { return(schema.EntityTypes.Cast <NamedStructuralType>() .Concat(schema.ComplexTypes.Cast <NamedStructuralType>()) .SelectMany(e => e.Properties) .Any(p => p.Annotations.OfType <StoreGeneratedPatternAnnotation>().Any())); }
/// <summary> /// Converts a model from Taupo term into Edm term /// </summary> /// <param name="taupoModel">The input model in Taupo term</param> /// <returns>The output model in Edm term</returns> public IEdmModel ConvertToEdmModel(EntityModelSchema taupoModel) { IEnumerable <XElement> csdlElements = this.GenerateCsdlElements(taupoModel); IEdmModel resultEdmModel = this.GetParserResult(csdlElements); return(resultEdmModel); }
/// <summary> /// Initializes a new instance of the ClrBasedQueryProvider type /// </summary> /// <param name="clrTypesAssembly">The assembly which contains the clr types for resource types</param> /// <param name="modelSchema">The schema for the model under test</param> /// <param name="evaluator">The evaluator to evaluate queries created after resolution</param> /// <param name="repository">The query repository to find root queries in</param> public ClrBasedQueryProvider(Assembly clrTypesAssembly, EntityModelSchema modelSchema, IQueryExpressionEvaluator evaluator, QueryRepository repository) { this.clrTypesAssembly = clrTypesAssembly; this.modelSchema = modelSchema; this.evaluator = evaluator; this.queryRepository = repository; }
/// <summary> /// Runs the given query against the OdataLib's uri translator and compares the results against an inmemorycontext /// </summary> /// <param name="expression">The query expression to run against the Uri parser</param> public void Verify(QueryExpression expression) { // 1. test : take the expression and construct the OData URI // /Customers?$top=1 string queryFragment = null; queryFragment = this.UriQueryVisitor.ComputeUri(expression); Uri serviceBaseUri = new Uri("http://localhost:9000/"); // http://localhost:9000/Customers?$top=1 Uri queryUri = new Uri(serviceBaseUri, queryFragment); this.Logger.WriteLine(LogLevel.Info, "Running Uri :{0}", queryUri.OriginalString); EntityModelSchema schema = Workspace.ConceptualModel; // Generate an EDM model based on the EntityModelSchema to use in the UriParser IEdmModel model = this.DataServiceProviderFactory.CreateMetadataProvider(schema); // Generate an IDSQP based on the EntityModelSchema to use in the Expression Translator var queryResolver = this.DataServiceProviderFactory.CreateQueryProvider(schema); // 2. product : take the URI , run it through the parser and get the Linq expression ODataUriParser parser = new ODataUriParser(model, serviceBaseUri, queryUri); var query = parser.ParseUri(); var result = query.Path; // Get the expected Results QueryValue expectedResults = null; expectedResults = this.Evaluator.Evaluate(expression); }
private GenericTypeLookupGraph BuildGenericTypeResolutionGraph(EntityModelSchema model) { var graph = new GenericTypeLookupGraph(); foreach (var unmappedBaseType in model.EntityTypes.Where(e => (e.Annotations.OfType <ObjectLayerOnlyAnnotation>().Any() || e.Annotations.OfType <GenericTypeAnnotation>().Any()) && e.BaseType == null)) { var genericTypeAnnotation = unmappedBaseType.Annotations.OfType <GenericTypeAnnotation>().FirstOrDefault(); if (genericTypeAnnotation == null) { continue; } int count = genericTypeAnnotation.TypeParameters.Count; for (int i = 0; i < count; ++i) { var lookups = new Dictionary <EntityType, GenericArgument>(); var typeParameterName = genericTypeAnnotation.TypeParameters[i]; graph.Add(new GenericTypeParameter(unmappedBaseType, typeParameterName), lookups); this.WalkChildren(graph, model, unmappedBaseType, typeParameterName, lookups); } } return(graph); }
private void ApplyEntityTypeCollectionTypes(EntityModelSchema model) { foreach (var entityType in model.EntityTypes) { foreach (var property in entityType.Properties.Where(p => p.PropertyType is CollectionDataType)) { if (!property.Annotations.OfType <CollectionContractTypeAnnotation>().Any()) { property.Annotations.Add(this.CreateContractTypeAnnotation()); } if (!property.Annotations.OfType <CollectionInstanceTypeAnnotation>().Any()) { property.Annotations.Add(this.CreateInstanceTypeAnnotation()); } } foreach (var navigation in entityType.NavigationProperties.Where(p => p.ToAssociationEnd.Multiplicity == EndMultiplicity.Many)) { if (!navigation.Annotations.OfType <CollectionContractTypeAnnotation>().Any()) { navigation.Annotations.Add(this.CreateContractTypeAnnotation()); } if (!navigation.Annotations.OfType <CollectionInstanceTypeAnnotation>().Any()) { navigation.Annotations.Add(this.CreateInstanceTypeAnnotation()); } } } }
/// <summary> /// Compares the two models to each other and throws an exception when there is an erro /// </summary> /// <param name="expectedTestEntityModel">EntityModelSchema to compare y to</param> /// <param name="actualEntityModelSchema">EntityModelSchema to compare x to</param> /// <returns>List of errors</returns> public ICollection <string> Compare(EntityModelSchema expectedTestEntityModel, EntityModelSchema actualEntityModelSchema) { this.errors = new List <string>(); foreach (ComplexType complexType in expectedTestEntityModel.ComplexTypes) { List <ComplexType> complexTypes = actualEntityModelSchema.ComplexTypes.Where(ct => ct.FullName == complexType.FullName).ToList(); if (!this.WriteErrorIfFalse(complexTypes.Count == 1, "Cannot find complexType '{0}'", complexType.Name)) { ComplexType ycomplexType = complexTypes.Single(); this.CompareComplexType(complexType, ycomplexType); } } foreach (EntityType expectedEntityType in expectedTestEntityModel.EntityTypes) { List <EntityType> entityTypes = actualEntityModelSchema.EntityTypes.Where(et => et.FullName == expectedEntityType.FullName).ToList(); if (!this.WriteErrorIfFalse(entityTypes.Count == 1, "Cannot find entityType '{0}'", expectedEntityType.Name)) { EntityType actualEntityType = entityTypes.Single(); this.CompareEntityTypes(expectedEntityType, actualEntityType); } } foreach (EntityContainer expectedEntityContainer in expectedTestEntityModel.EntityContainers) { List <EntityContainer> entityContainers = actualEntityModelSchema.EntityContainers.Where(ec => ec.Name == expectedEntityContainer.Name).ToList(); if (!this.WriteErrorIfFalse(entityContainers.Count == 1, "Cannot find entityContainer '{0}'", expectedEntityContainer.Name)) { EntityContainer actualEntityContainer = entityContainers.Single(); this.CompareEntityContainer(expectedEntityContainer, actualEntityContainer); } } return(this.errors); }
public void ConvertFunction_with_overloads() { var taupoModel = new EntityModelSchema() { new Function("NS1", "MyFunction") { new FunctionParameter("Param1", EdmDataTypes.Int32, FunctionParameterMode.InOut), new FunctionParameter("Param2", EdmDataTypes.Int32, FunctionParameterMode.Out) }, new Function("NS1", "MyFunction") { new FunctionParameter("Param", EdmDataTypes.Int16), }, }; IEdmModel result = this.converter.ConvertToEdmModel(taupoModel); Assert.AreEqual(2, result.SchemaElements.Count()); Assert.AreEqual(2, result.SchemaElements.OfType <IEdmOperation>().Count()); IEdmOperation operation = result.SchemaElements.OfType <IEdmOperation>().ElementAt(0); Assert.AreEqual("NS1.MyFunction", operation.FullName()); Assert.AreEqual(2, operation.Parameters.Count()); Assert.AreEqual("Param1", operation.Parameters.ElementAt(0).Name); Assert.AreEqual("Param2", operation.Parameters.ElementAt(1).Name); operation = result.SchemaElements.OfType <IEdmOperation>().ElementAt(1); Assert.AreEqual("NS1.MyFunction", operation.FullName()); Assert.AreEqual(1, operation.Parameters.Count()); Assert.AreEqual("Param", operation.Parameters.ElementAt(0).Name); }
/// <summary> /// Add default EntityContainer to the given EntitySchemaModel /// For each base entity type, add an EntitySet /// For each association, add an AssociationSet, between two possible EntitySets /// </summary> /// <param name="model">the given EntitySchemaModel</param> public void Fixup(EntityModelSchema model) { EntityContainer container = model.EntityContainers.FirstOrDefault(); if (container == null) { container = new EntityContainer(this.DefaultContainerName); model.Add(container); } foreach (EntityType entity in model.EntityTypes.Where(e => e.BaseType == null && !container.EntitySets.Any(set => set.EntityType == e))) { if (!entity.Annotations.OfType <FixupNoSetAnnotation>().Any()) { container.Add(new EntitySet(entity.Name, entity)); } } foreach (AssociationType association in model.Associations.Where(assoc => !container.AssociationSets.Any(assocSet => assocSet.AssociationType == assoc))) { if (!association.Annotations.OfType <FixupNoSetAnnotation>().Any()) { container.Add(new AssociationSet(association.Name, association) { Ends = { new AssociationSetEnd(association.Ends[0], container.EntitySets.First(es => association.Ends[0].EntityType.IsKindOf(es.EntityType))), new AssociationSetEnd(association.Ends[1], container.EntitySets.First(es => association.Ends[1].EntityType.IsKindOf(es.EntityType))), } }); } } }
/// <summary> /// Visits a model /// </summary> /// <param name="model">model to visit</param> public void Visit(EntityModelSchema model) { foreach (var entity in model.EntityTypes) { this.VisitEntityType(entity); } foreach (var complex in model.ComplexTypes) { this.VisitComplexType(complex); } foreach (var association in model.Associations) { this.VisitAssociationType(association); } foreach (var container in model.EntityContainers) { this.VisitEntityContainer(container); } foreach (var function in model.Functions) { this.VisitFunction(function); } foreach (var enumType in model.EnumTypes) { this.VisitEnumType(enumType); } }
/// <summary> /// Remove named streams and corresponding features in model for EF provider /// </summary> /// <param name="model">The model to fix up</param> public void Fixup(EntityModelSchema model) { foreach (var entityType in model.EntityTypes) { entityType.Properties.RemoveAll(p => p.IsStream()); } }
/// <summary> /// Generates the top-level namespace declarations. /// </summary> /// <param name="model">The entity schema model.</param> /// <returns> /// Sequence of top-level namespace declaration attributes. /// </returns> protected virtual IEnumerable <XAttribute> GenerateNamespaceDeclarations(EntityModelSchema model) { if (this.GenerateTaupoAnnotations) { yield return(new XAttribute(XNamespace.Xmlns + "taupo", EdmConstants.TaupoAnnotationsNamespace.NamespaceName)); } }
/// <summary> /// Annotates the model based on the POCO Generation options. /// </summary> /// <param name="model">The EntityModelSchema that has to be annotated</param> /// <param name="option">The POCOGeneration option for model annotation</param> public static void Annotate(EntityModelSchema model, PocoOption option) { ExceptionUtilities.CheckArgumentNotNull(model, "model"); switch (option) { case PocoOption.None: break; case PocoOption.Pure: CustomizeModelForPurePocoGeneration(model); break; case PocoOption.NavigationPropertiesVirtual: CustomizeModelForPocoGenerationWithNavigationPropertiesVirtual(model); break; case PocoOption.AllPropertiesVirtual: CustomizeModelForPocoGenerationWithAllPropertiesVirtual(model); break; default: throw new TaupoArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid Poco option '{0}' specified. Use any of the allowed Poco option values such as '{1}', '{2}', '{3}' or '{4}' instead!", option, PocoOption.None, PocoOption.Pure, PocoOption.NavigationPropertiesVirtual, PocoOption.AllPropertiesVirtual)); } }
private void ResolveNavigationProperty(EntityModelSchema model, NavigationProperty nav) { nav.Association = this.ResolveAssociationTypeReference(model, nav.Association); nav.FromAssociationEnd = this.ResolveAssociationEndReference(nav.Association, nav.FromAssociationEnd); nav.ToAssociationEnd = this.ResolveAssociationEndReference(nav.Association, nav.ToAssociationEnd); }