/// <summary> /// Creates the object services. /// </summary> /// <param name="modelSchema">The entity model schema.</param> /// <param name="conceptualDataServices">The structural generators for the specified entity model schema</param> /// <param name="assemblies">The assemblies that contain data classes for the specified entity model schema.</param> /// <returns>Entity model object services.</returns> public IEntityModelObjectServices CreateObjectServices(EntityModelSchema modelSchema, IEntityModelConceptualDataServices conceptualDataServices, IEnumerable <Assembly> assemblies) { ExceptionUtilities.CheckArgumentNotNull(modelSchema, "modelSchema"); ExceptionUtilities.CheckArgumentNotNull(conceptualDataServices, "conceptualDataServices"); ExceptionUtilities.CheckArgumentNotNull(assemblies, "assemblies"); EntityModelObjectServices services = new EntityModelObjectServices(conceptualDataServices); this.RegisterDataGeneratorAndAdaptersForComplexTypes(modelSchema, conceptualDataServices, services, assemblies); List <EntityType> processedEntityTypes = new List <EntityType>(); foreach (EntityContainer entityContainer in modelSchema.EntityContainers) { var graphCreator = new EntityGraphCreator(entityContainer) { ConceptualDataServices = conceptualDataServices, ObjectServices = services, Random = this.Random }; services.RegisterGraphCreator(graphCreator, entityContainer); foreach (EntitySet entitySet in entityContainer.EntitySets) { string entitySetName = entityContainer.Name + "." + entitySet.Name; foreach (EntityType entityType in modelSchema.EntityTypes.Where(t => t.IsKindOf(entitySet.EntityType) && !t.IsAbstract)) { INamedValuesGenerator structuralGenerator = conceptualDataServices.GetStructuralGenerator(entityType.FullName, entitySetName); Type clrType = this.GetClrType(entityType, assemblies); IStructuralDataAdapter adapter = new ObjectStructuralDataAdapter(clrType); IDataGenerator objectDataGen = this.CreateObjectDataGenerator(clrType, adapter, structuralGenerator); EntitySetObjectDataGenerator entitySetObjectDataGen = new EntitySetObjectDataGenerator(entitySetName, objectDataGen); services.RegisterEntitySetDataGenerator(entitySetObjectDataGen, entityType, entitySetName); services.RegisterDataGenerator(objectDataGen, entityType, entitySetName); if (!processedEntityTypes.Contains(entityType)) { services.RegisterDataAdapter(adapter, entityType); this.RegisterEnumTypes(entityType, services, assemblies); } processedEntityTypes.Add(entityType); } } } return(services); }
private void RegisterDataGeneratorAndAdaptersForComplexTypes(EntityModelSchema model, IEntityModelConceptualDataServices structuralDataServices, EntityModelObjectServices services, IEnumerable <Assembly> assemblies) { foreach (ComplexType complexType in model.ComplexTypes) { INamedValuesGenerator structuralGenerator = structuralDataServices.GetStructuralGenerator(complexType.FullName); Type clrType = this.GetClrType(complexType, assemblies); IStructuralDataAdapter adapter = new ObjectStructuralDataAdapter(clrType); IDataGenerator objectDataGen = this.CreateObjectDataGenerator(clrType, adapter, structuralGenerator); services.RegisterDataGenerator(objectDataGen, complexType); services.RegisterDataAdapter(adapter, complexType); } }