internal virtual CollectionColumnMap CreateColumnMapFromReaderAndType( DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet, Dictionary <string, FunctionImportReturnTypeStructuralTypeColumnRenameMapping> renameList) { ColumnMap[] columnMapsForType = ColumnMapFactory.GetColumnMapsForType(storeDataReader, edmType, renameList); ColumnMap elementMap = (ColumnMap)null; if (Helper.IsRowType((GlobalItem)edmType)) { elementMap = (ColumnMap) new RecordColumnMap(TypeUsage.Create(edmType), edmType.Name, columnMapsForType, (SimpleColumnMap)null); } else if (Helper.IsComplexType(edmType)) { elementMap = (ColumnMap) new ComplexTypeColumnMap(TypeUsage.Create(edmType), edmType.Name, columnMapsForType, (SimpleColumnMap)null); } else if (Helper.IsScalarType(edmType)) { if (storeDataReader.FieldCount != 1) { throw new EntityCommandExecutionException(Strings.ADP_InvalidDataReaderFieldCountForScalarType); } elementMap = (ColumnMap) new ScalarColumnMap(TypeUsage.Create(edmType), edmType.Name, 0, 0); } else if (Helper.IsEntityType(edmType)) { elementMap = (ColumnMap)ColumnMapFactory.CreateEntityTypeElementColumnMap(storeDataReader, edmType, entitySet, columnMapsForType, (Dictionary <string, FunctionImportReturnTypeStructuralTypeColumnRenameMapping>)null); } return((CollectionColumnMap) new SimpleCollectionColumnMap(edmType.GetCollectionType().TypeUsage, edmType.Name, elementMap, (SimpleColumnMap[])null, (SimpleColumnMap[])null)); }
// <summary> // Build the collectionColumnMap from a store datareader, a type and an entitySet. // </summary> internal virtual CollectionColumnMap CreateColumnMapFromReaderAndType( DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet, Dictionary <string, FunctionImportReturnTypeStructuralTypeColumnRenameMapping> renameList) { Debug.Assert( Helper.IsEntityType(edmType) || null == entitySet, "The specified non-null EntitySet is incompatible with the EDM type specified."); // Next, build the ColumnMap directly from the edmType and entitySet provided. var propertyColumnMaps = GetColumnMapsForType(storeDataReader, edmType, renameList); ColumnMap elementColumnMap = null; // NOTE: We don't have a null sentinel here, because the stored proc won't // return one anyway; we'll just presume the data's always there. if (Helper.IsRowType(edmType)) { elementColumnMap = new RecordColumnMap(TypeUsage.Create(edmType), edmType.Name, propertyColumnMaps, null); } else if (Helper.IsComplexType(edmType)) { elementColumnMap = new ComplexTypeColumnMap(TypeUsage.Create(edmType), edmType.Name, propertyColumnMaps, null); } else if (Helper.IsScalarType(edmType)) { if (storeDataReader.FieldCount != 1) { throw new EntityCommandExecutionException(Strings.ADP_InvalidDataReaderFieldCountForScalarType); } elementColumnMap = new ScalarColumnMap(TypeUsage.Create(edmType), edmType.Name, 0, 0); } else if (Helper.IsEntityType(edmType)) { elementColumnMap = CreateEntityTypeElementColumnMap( storeDataReader, edmType, entitySet, propertyColumnMaps, null /*renameList*/); } else { Debug.Assert(false, "unexpected edmType?"); } CollectionColumnMap collection = new SimpleCollectionColumnMap( edmType.GetCollectionType().TypeUsage, edmType.Name, elementColumnMap, null, null); return(collection); }
private static EdmFunction CreateFunctionImport(DbModel model, FunctionDescriptor descriptor) { var parameters = descriptor.Parameters.Select(p => { TypeUsage typeUsage = GetTypeUsage(GetSimpleEdmType(model, p.Type), p); return(FunctionParameter.Create(p.Name, typeUsage.EdmType, p.Direction == ParameterDirection.Output ? ParameterMode.Out : p.Direction == ParameterDirection.InputOutput ? ParameterMode.InOut : p.Direction == ParameterDirection.ReturnValue ? ParameterMode.ReturnValue : ParameterMode.In)); }).ToArray(); var entitySets = new EntitySet[descriptor.Results.Count]; var results = descriptor.Results.Select((r, i) => { EdmType edmType = GetStructuralEdmType(model, r.Type); if (edmType == null) { edmType = GetTypeUsage(GetSimpleEdmType(model, r.Type), r).EdmType; } entitySets[i] = edmType.BuiltInTypeKind != BuiltInTypeKind.EntityType ? null : model.ConceptualModel.Container.EntitySets.FirstOrDefault(s => edmType.Yield(t => t.BaseType, (t, b) => b, t => t != null).Contains(s.ElementType)); return(FunctionParameter.Create(string.Format("Result_{0}", i), edmType.GetCollectionType(), ParameterMode.ReturnValue)); }).ToArray(); var payload = new EdmFunctionPayload { StoreFunctionName = descriptor.FunctionName, IsFunctionImport = true, IsAggregate = descriptor.IsAggregate, IsBuiltIn = descriptor.IsBuiltIn, IsComposable = descriptor.IsComposable, IsNiladic = descriptor.IsNiladic, ParameterTypeSemantics = descriptor.ParameterTypeSemantics, Schema = descriptor.DatabaseSchema, Parameters = parameters, ReturnParameters = results, EntitySets = entitySets, }; return(EdmFunction.Create(descriptor.FunctionName, model.ConceptualModel.Container.Name, DataSpace.CSpace, payload, null)); }