private Assembly CreateDynamicControllersAssembly(BoundedContextElement boundedContextElement) { var assemblyModuleName = boundedContextElement.Identity.Id.Segments.LastOrDefault() + "Controllers"; var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(assemblyModuleName), AssemblyBuilderAccess.Run); var moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyModuleName); var entities = boundedContextElement.ConceptualModel.Entities.Where(x => !string.IsNullOrEmpty(x.EntitySetName)); foreach (var entity in entities) { var entityType = _clrTypeProvider.Get(entity.Identity); var parentType = typeof(GenericODataController <>).MakeGenericType(entityType); var controllerTypeName = entity.EntitySetName + "Controller"; var typeBuilder = moduleBuilder.DefineType(controllerTypeName, TypeAttributes.Public | TypeAttributes.Sealed, parentType); AddParentConstructor(typeBuilder, parentType); AddEntityElementIdAnnotation(typeBuilder, entity); AddContainmentEntitiesMethods(typeBuilder, parentType, entity, entityType); typeBuilder.CreateType(); } return(assemblyBuilder); }
public void Annotate(IMetadataElement metadataElement, IEdmElement edmElement, IEdmModel edmModel) { if (metadataElement is EntityElement || metadataElement is EnumTypeElement) { var clrType = _clrTypeProvider.Get(metadataElement.Identity); if (clrType != null) { edmModel.SetAnnotationValue(edmElement, new ClrTypeAnnotation(clrType)); } } }