Example #1
0
        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, MetadataMismatchTypes.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, MetadataMismatchTypes.InconsistentCLRPropertyDefinition, detail);
                return(null);
            }

            CheckProperty(dp, dp.ComplexType.Name, complexTypeName, "ComplexTypeName");
            return(dp);
        }
Example #2
0
        private DataProperty ParseCsdlDataProperty(StructuralType parentType, JObject csdlProperty, List <String> keyNamesOnServer)
        {
            DataProperty dp;
            var          typeParts = ExtractTypeNameParts(csdlProperty);

            if (typeParts.Length == 2)
            {
                dp = ParseCsdlSimpleProperty(parentType, csdlProperty, keyNamesOnServer);
            }
            else
            {
                if (IsEnumType(csdlProperty))
                {
                    dp = ParseCsdlSimpleProperty(parentType, csdlProperty, keyNamesOnServer);
                    dp.EnumTypeName = (String)csdlProperty["type"];
                }
                else
                {
                    dp = ParseCsdlComplexProperty(parentType, csdlProperty);
                }
            }

            if (dp != null)
            {
                AddValidators(dp);
            }
            return(dp);
        }
        internal void CheckStructuralType(StructuralType stType, Object v1, Object v2, String name)
        {
            if (v1 == null && v2 == null)
            {
                return;
            }
            if (Object.Equals(v1, v2))
            {
                return;
            }
            var detail = String.Format("Type property: {0}, Client value: '{1}',  Server value: '{2}'",
                                       name, (v1 ?? "").ToString(), (v2 ?? "").ToString());

            MetadataStore.OnMetadataMismatch(stType.Name, null, MetadataMismatchType.InconsistentCLRTypeDefinition, detail);
        }
 private static void UpdateBaseProperties(StructuralType structuralType, StructuralType baseStructuralType)
 {
     baseStructuralType.DataProperties.ForEach(dp => {
         var newDp = new DataProperty(dp);
         structuralType.AddDataProperty(newDp);
     });
     if (baseStructuralType.IsEntityType)
     {
         var entityType     = (EntityType)structuralType;
         var baseEntityType = (EntityType)baseStructuralType;
         baseEntityType.NavigationProperties.ForEach(np => {
             var newNp = new NavigationProperty(np);
             entityType.AddNavigationProperty(newNp);
         });
     }
 }
Example #5
0
        private void AddStructuralType(StructuralType stType, bool allowMerge = true)
        {
            // don't register anon types
            if (stType.IsAnonymous)
            {
                return;
            }

            lock (_structuralTypes) {
                if (_structuralTypes.ContainsKey(stType.Name))
                {
                    throw new Exception("Type " + stType.Name + " already exists in this MetadataStore.");
                }

                _structuralTypes.Add(stType);
                _shortNameMap[stType.ShortName] = stType.Name;
            }
        }
            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);
                }
            }
Example #7
0
        private static DataProperty CreateDataProperty(StructuralType structuralType, PropertyInfo pInfo)
        {
            var propType = pInfo.PropertyType;
            var dp       = new DataProperty(pInfo.Name);

            // TODO: handle isScalar
            if (typeof(IComplexObject).IsAssignableFrom(propType))
            {
                dp.ComplexType = GetComplexType(propType);
                dp.IsNullable  = false;
                // complex Objects do not have defaultValues currently
            }
            else
            {
                dp.ClrType      = propType;
                dp.DataType     = DataType.FromClrType(TypeFns.GetNonNullableType(propType));
                dp.IsNullable   = TypeFns.IsNullableType(propType);
                dp.DefaultValue = dp.IsNullable ? null : dp.DataType.DefaultValue;
            }

            structuralType.AddDataProperty(dp);
            return(dp);
        }
Example #8
0
        public String TestPropertyName(String testVal, StructuralType parentType, bool toServer)
        {
            Func <String, StructuralType, String> fn1;
            Func <String, StructuralType, String> fn2;

            if (toServer)
            {
                fn1 = ClientPropertyNameToServer;
                fn2 = ServerPropertyNameToClient;
            }
            else
            {
                fn1 = ServerPropertyNameToClient;
                fn2 = ClientPropertyNameToServer;
            }
            var t1 = fn1(testVal, parentType);
            var t2 = fn2(t1, parentType);

            if (t2 != testVal)
            {
                throw new Exception("NamingConvention: " + this.Name + " does not roundtrip the following value correctly: " + testVal);
            }
            return(t1);
        }
        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);
        }
Example #10
0
 /// <summary>
 /// Translates a server property name into a client property name.
 /// </summary>
 /// <param name="clientName"></param>
 /// <param name="parentType"></param>
 /// <returns></returns>
 public virtual String ServerPropertyNameToClient(String clientName, StructuralType parentType)
 {
     return(clientName);
 }
Example #11
0
 public override String ClientPropertyNameToServer(String clientName, StructuralType parentType)
 {
     return(clientName.Substring(0, 1).ToUpper() + clientName.Substring(1));
 }
Example #12
0
 public override String ServerPropertyNameToClient(String serverName, StructuralType parentType)
 {
     return(serverName.Substring(0, 1).ToLower() + serverName.Substring(1));
 }
Example #13
0
 /// <summary>
 /// Translates a server property name into a client property name.
 /// </summary>
 /// <param name="serverName"></param>
 /// <param name="parentType"></param>
 /// <returns></returns>
 public virtual String ClientPropertyNameToServer(String serverName, StructuralType parentType)
 {
     return(serverName);
 }
 internal Type GetClrTypeFor(StructuralType stType)
 {
     lock (_structuralTypes) {
         return(_clrTypeMap.GetClrType(stType));
     }
 }