Esempio n. 1
0
        static IDictionary <string, MethodInfo> FindApartFields(Type interfaceType, RelationVersionInfo versionInfo)
        {
            var result  = new Dictionary <string, MethodInfo>();
            var pks     = versionInfo.GetPrimaryKeyFields().ToDictionary(tfi => tfi.Name, tfi => tfi);
            var methods = interfaceType.GetMethods();

            for (var i = 0; i < methods.Length; i++)
            {
                var method = methods[i];
                if (!method.Name.StartsWith("get_"))
                {
                    continue;
                }
                var            name = method.Name.Substring(4);
                TableFieldInfo tfi;
                if (!pks.TryGetValue(name, out tfi))
                {
                    throw new BTDBException($"Property {name} is not part of primary key.");
                }
                if (method.ReturnType != tfi.Handler.HandledType())
                {
                    throw new BTDBException($"Property {name} has different return type then member of primary key with the same name.");
                }
                result.Add(name, method);
            }
            return(result);
        }
Esempio n. 2
0
        static void CheckThatPrimaryKeyHasNotChanged(string name, RelationVersionInfo info, RelationVersionInfo previousInfo)
        {
            var pkFields     = info.GetPrimaryKeyFields();
            var prevPkFields = previousInfo.GetPrimaryKeyFields();

            if (pkFields.Count != prevPkFields.Count)
            {
                throw new BTDBException($"Change of primary key in relation '{name}' is not allowed. Field count {pkFields.Count} != {prevPkFields.Count}.");
            }
            var en  = pkFields.GetEnumerator();
            var pen = prevPkFields.GetEnumerator();

            while (en.MoveNext() && pen.MoveNext())
            {
                if (!ArePrimaryKeyFieldsCompatible(en.Current.Handler, pen.Current.Handler))
                {
                    throw new BTDBException($"Change of primary key in relation '{name}' is not allowed. Field '{en.Current.Name}' is not compatible.");
                }
            }
        }