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 = GetClientTypeNameFromClrTypeName((String)csdlProperty["type"]); // can't set the name until we go thru namingConventions and these need the dp. var nameOnServer = (String)csdlProperty["name"]; var name = NamingConvention.ServerPropertyNameToClient(nameOnServer, parentType); var dp = parentType.GetDataProperty(name); if (dp == null) { MetadataStore.OnMetadataMismatch(parentType.Name, name, MetadataMismatchType.MissingCLRDataProperty); return(null); } if (!dp.IsComplexProperty) { var detail = "Defined as a ComplexProperty on the server but not on the client"; MetadataStore.OnMetadataMismatch(parentType.Name, name, MetadataMismatchType.InconsistentCLRPropertyDefinition, detail); return(null); } CheckProperty(dp, dp.ComplexType.Name, complexTypeName, "ComplexTypeName"); return(dp); }
private DataProperty ParseCsdlSimpleProperty(StructuralType parentType, JObject csdlProperty, List <String> keyNamesOnServer) { var typeVal = (String)csdlProperty["type"]; var nameVal = (String)csdlProperty["name"]; var nullableVal = (String)csdlProperty["nullable"]; var maxLengthVal = (String)csdlProperty["maxLength"]; var concurrencyModeVal = (String)csdlProperty["concurrencyMode"]; var dataType = DataType.FromEdmType(typeVal); if (dataType == DataType.Undefined) { parentType.Warnings.Add("Unable to recognize DataType for property: " + nameVal + " DateType: " + typeVal); } var dpName = NamingConvention.ServerPropertyNameToClient(nameVal, parentType); var dp = parentType.GetDataProperty(dpName); if (dp == null) { MetadataStore.OnMetadataMismatch(parentType.Name, dpName, MetadataMismatchType.MissingCLRDataProperty); return(null); } var isNullable = nullableVal == "true" || nullableVal == null; var entityType = parentType as EntityType; bool isPartOfKey = false; bool isAutoIncrementing = false; if (entityType != null) { isPartOfKey = keyNamesOnServer != null && keyNamesOnServer.IndexOf(nameVal) >= 0; if (isPartOfKey && entityType.AutoGeneratedKeyType == AutoGeneratedKeyType.None) { if (IsIdentityProperty(csdlProperty)) { isAutoIncrementing = true; entityType.AutoGeneratedKeyType = AutoGeneratedKeyType.Identity; } } } Object defaultValue; var rawDefaultValue = csdlProperty["defaultValue"]; if (rawDefaultValue == null) { defaultValue = isNullable ? null : dataType.DefaultValue; } else { defaultValue = rawDefaultValue.ToObject(dataType.ClrType); } // TODO: nit - don't set maxLength if null; var maxLength = (maxLengthVal == null || maxLengthVal == "Max") ? (Int64?)null : Int64.Parse(maxLengthVal); var concurrencyMode = concurrencyModeVal == "fixed" ? ConcurrencyMode.Fixed : ConcurrencyMode.None; CheckProperty(dp, dp.DataType, dataType, "DataType"); CheckProperty(dp, dp.IsScalar, true, "IsScalar"); dp.IsPartOfKey = isPartOfKey; dp.IsNullable = isNullable; dp.MaxLength = maxLength; dp.DefaultValue = defaultValue; // fixedLength: fixedLength, dp.ConcurrencyMode = concurrencyMode; dp.IsAutoIncrementing = isAutoIncrementing; if (dataType == DataType.Undefined) { dp.RawTypeName = typeVal; } return(dp); }