Exemple #1
0
        // internal extension methods - IIndexer is an internal interface
        internal static bool TryGetIndex <TModel, TProperty>(this IIndexer indexer, Expression <Func <TModel, TProperty> > propExpr, out IIndex index)
        {
            index = null;
            // we can get the name of the property
            var member = propExpr.Body as MemberExpression;
            var prop   = member.Member;

            return(indexer.TryGetIndex(new DataValue(typeof(TProperty), DataAttributes.Index).Value(prop.Name), out index));
        }
Exemple #2
0
            /*
             * If data does not have an ID then a key is generated on the fly.
             * ***/
            private bool CheckConstraints(IIndexer indexer, object[] data, out DataValue key)
            {
                var passConstraints = true;

                key = new DataValue(DataType.Int, Attribs.PKey);

                var idx = 0;

                while (passConstraints && idx < data.Length)
                {
                    var    field = Fields[idx];
                    IIndex index;

                    if (field.Is(Attribs.PKey))
                    {
                        key = new DataValue(field.Type, field.Attributes);

                        if (field.Is(Attribs.AutoIncr))
                        {
                            // even if a real value is supplied, an AutoIncr attribute will
                            // overwrite with the appropriate value
                            if (data[idx] is DataValue)
                            {
                                key = ((DataValue)data[idx]).Value(mIndexer());
                            }
                            else
                            {
                                key = key.Value(mIndexer());
                            }

                            passConstraints = (data[idx] = key.Value()) != null;

                            // check indexer constraints - true if valid
                            if (indexer.TryGetIndex(key, out index))
                            {
                                passConstraints &= index.Add(mCache.NextRowId, key);
                            }
                        }
                    }
                    else if (field.Is(Attribs.AutoIncr))
                    {
                        // even if a real value is supplied, an AutoIncr attribute will
                        // overwrite with the appropriate value
                        if (data[idx] is DataValue)
                        {
                            key = ((DataValue)data[idx]).Value(mIndexer());
                        }
                        else
                        {
                            key = key.Value(mIndexer());
                        }

                        passConstraints = (data[idx] = key.Value()) != null;

                        // check indexer constraints - true if valid
                        if (indexer.TryGetIndex(key, out index))
                        {
                            passConstraints &= index.Add(mCache.NextRowId, key);
                        }
                    }
                    // check if assign default value
                    if (field.Is(Attribs.Default))
                    {
                        data[idx] = field.Data.Value();
                    }
                    // check add Index
                    if (!field.Is(Attribs.PKey) && field.Is(Attribs.Index))
                    {
                        key = new DataValue(field.Type, field.Attributes).Value(field.Name);
                        if (!indexer.TryGetIndex(key, out index))
                        {
                            // TODO: index error, missing index
                            passConstraints &= false;

                            break;
                        }

                        key              = key.Value(data[idx]);
                        passConstraints &= index.Add(mCache.NextRowId, key);
                    }

                    ++idx;
                }

                if (!passConstraints)
                {
                    passConstraints = (key = key.Value(mIndexer())).Value() != null;
                }

                return(passConstraints);
            }