private void UpdateComplexProperties(StructuralType structuralType) { structuralType.ComplexProperties.ForEach(cp => { if (cp.ComplexType != null) { return; } cp.DataType = null; cp.DefaultValue = null; var complexType = GetComplexType(cp.ComplexTypeName, true); if (complexType == null) { AddIncompleteComplexProperty(cp.ComplexTypeName, cp); } else { cp.ComplexType = complexType; } }); if (!structuralType.IsEntityType) { var incompleteProps = GetIncompleteComplexProperties(structuralType.Name); incompleteProps.ForEach(cp => cp.ComplexType = GetComplexType(cp.ComplexTypeName)); } }
private Tuple <EntityKey, EntityKey> ToEntityKeys(KeyMapping keyMapping) { var entityTypeName = StructuralType.ClrTypeNameToStructuralTypeName(keyMapping.EntityTypeName); var et = MetadataStore.Instance.GetEntityType(entityTypeName); var oldKey = new EntityKey(et, keyMapping.TempValue); var newKey = new EntityKey(et, keyMapping.RealValue); return(Tuple.Create(oldKey, newKey)); }
internal NavigationProperty AddNavigationProperty(NavigationProperty np) { np.ParentType = this; UpdateClientServerName(np); _navigationProperties.Add(np); if (!IsQualifiedTypeName(np.EntityTypeName)) { np.EntityTypeName = StructuralType.QualifyTypeName(np.EntityTypeName, this.Namespace); } return(np); }
protected virtual Object CreateAndPopulate(JsonContext jsonContext) { var jObject = jsonContext.JObject; JToken refToken = null; if (jObject.TryGetValue("$ref", out refToken)) { return(_refMap[refToken.Value <String>()]); } EntityType entityType; Type objectType; JToken typeToken = null; if (jObject.TryGetValue("$type", out typeToken)) { var clrTypeName = typeToken.Value <String>(); var entityTypeName = StructuralType.ClrTypeNameToStructuralTypeName(clrTypeName); entityType = _metadataStore.GetEntityType(entityTypeName); objectType = entityType.ClrType; if (!jsonContext.ObjectType.IsAssignableFrom(objectType)) { throw new Exception("Unable to convert returned type: " + objectType.Name + " into type: " + jsonContext.ObjectType.Name); } jsonContext.ObjectType = objectType; } else { objectType = jsonContext.ObjectType; entityType = _metadataStore.GetEntityType(objectType); } // an entity type jsonContext.StructuralType = entityType; var keyValues = entityType.KeyProperties .Select(p => jObject[p.Name].ToObject(p.ClrType)) .ToArray(); var entityKey = EntityKey.Create(entityType, keyValues); var entity = _entityManager.FindEntityByKey(entityKey); if (entity == null) { entity = (IEntity)Activator.CreateInstance(objectType); } // must be called before populate UpdateRefMap(jObject, entity); _allEntities.Add(entity); return(PopulateEntity(jsonContext, entity)); }
private TypeNameInfo ParseTypeName(String clrTypeName) { if (String.IsNullOrEmpty(clrTypeName)) { return(null); } if (clrTypeName.StartsWith(MetadataStore.ANONTYPE_PREFIX)) { return(new TypeNameInfo() { ShortTypeName = clrTypeName, Namespace = "", TypeName = clrTypeName, IsAnonymous = true, }); } var entityTypeNameNoAssembly = clrTypeName.Split(',')[0]; var nameParts = entityTypeNameNoAssembly.Split('.'); if (nameParts.Length > 1) { var shortName = nameParts[nameParts.Length - 1]; // var nsParts = nameParts.Take(nameParts.Length - 1).ToArray(); var ns = GetNamespaceFor(shortName); return(new TypeNameInfo() { ShortTypeName = shortName, Namespace = ns, TypeName = StructuralType.QualifyTypeName(shortName, ns) }); } else { return(new TypeNameInfo() { ShortTypeName = clrTypeName, Namespace = "", TypeName = clrTypeName }); } }
private DataProperty ParseCsdlComplexProperty(StructuralType parentType, JObject csdlProperty) { // Complex properties are never nullable ( per EF specs) // var isNullable = csdlProperty.nullable === 'true' || csdlProperty.nullable == null; var complexTypeName = ParseTypeName((String)csdlProperty["type"]).TypeName; // can't set the name until we go thru namingConventions and these need the dp. var dp = new DataProperty() { ParentType = parentType, NameOnServer = (String)csdlProperty["name"], ComplexTypeName = complexTypeName, IsNullable = false, IsScalar = true, ConcurrencyMode = ConcurrencyMode.None, }; return(dp); }
private void AddStructuralType(StructuralType stType, bool allowMerge = true) { lock (_structuralTypes) { // for now ignore dups // TODO: handle custom metadata later. if (_structuralTypes[stType.Name] != null) { return; } _clrTypeMap.GetClrType(stType); //// don't register anon types if (!stType.IsAnonymous) { if (_structuralTypes.ContainsKey(stType.Name)) { throw new Exception("Type " + stType.Name + " already exists in this MetadataStore."); } _structuralTypes.Add(stType); _shortNameMap[stType.ShortName] = stType.Name; } stType.Properties.ForEach(prop => stType.UpdateClientServerFkNames(prop)); UpdateComplexProperties(stType); var entityType = stType as EntityType; if (entityType != null) { UpdateNavigationProperties(entityType); // check if this structural type's name, short version or qualified version has a registered ctor. // structuralType.getEntityCtor(); if (entityType.BaseEntityType != null) { entityType.BaseEntityType.AddSubEntityType(entityType); } } } }
public Type GetClrType(StructuralType stType) { TypePair tp; if (_map.TryGetValue(stType.Name, out tp)) { stType.ClrType = tp.ClrType; if (tp.StructuralType == null) { tp.StructuralType = stType; } return(tp.ClrType); } else { _map.Add(stType.Name, new TypePair() { StructuralType = stType }); return(null); } }
public StructuralType GetStructuralType(Type clrType) { var stName = StructuralType.ClrTypeToStructuralTypeName(clrType); TypePair tp; if (_map.TryGetValue(stName, out tp)) { var stType = tp.StructuralType; if (tp.ClrType == null) { tp.ClrType = clrType; ProbeAssemblies(new Assembly[] { clrType.GetTypeInfo().Assembly }); } return(stType); } else { _map.Add(stName, new TypePair() { ClrType = clrType }); return(null); } }
private String NormalizeEntityTypeName(String clrTypeName) { if (String.IsNullOrEmpty(clrTypeName)) { return(null); } var entityTypeNameNoAssembly = clrTypeName.Split(',')[0]; var nameParts = entityTypeNameNoAssembly.Split('.'); String ns; var shortName = nameParts[nameParts.Length - 1]; if (nameParts.Length > 1) { ns = String.Join(".", nameParts.Take(nameParts.Length - 1)); } else { ns = ""; } var typeName = StructuralType.QualifyTypeName(shortName, ns); return(typeName); }
internal Type GetClrTypeFor(StructuralType stType) { lock (_structuralTypes) { return(_clrTypeMap.GetClrType(stType)); } }