public void OnReturn(IRetrieveRequestHandler handler)
        {
            if (Target is null ||
                !handler.AllowSelectField(Target) ||
                !handler.ShouldSelectField(Target))
            {
                return;
            }

            var idField = handler.Row.IdField;

            var listHandler = handlerFactory.CreateHandler <IListRequestProcessor>(rowType);
            var listRequest = listHandler.CreateRequest();

            listRequest.ColumnSelection = ColumnSelection.KeyOnly;
            listRequest.IncludeColumns  = new HashSet <string>
            {
                itemKeyField.PropertyName ?? itemKeyField.Name
            };
            listRequest.Criteria = thisKeyCriteria == new ValueCriteria(idField.AsObject(handler.Row)) & filterCriteria;

            IListResponse response = listHandler.Process(handler.Connection, listRequest);

            var list = listFactory();

            foreach (IRow item in response.Entities)
            {
                list.Add(itemKeyField.AsObject(item));
            }

            Target.AsObject(handler.Row, list);
        }
        public void OnReturn(IRetrieveRequestHandler handler)
        {
            if (Target is null ||
                !handler.AllowSelectField(Target) ||
                !handler.ShouldSelectField(Target))
            {
                return;
            }

            var listHandler = handlerFactory.CreateHandler <IListRequestProcessor>(rowType);
            var listRequest = listHandler.CreateRequest();

            listRequest.ColumnSelection = attr.ColumnSelection;
            listRequest.IncludeColumns  = includeColumns;
            listRequest.Criteria        = foreignKeyCriteria == new ValueCriteria(masterKeyField.AsObject(handler.Row)) & filterCriteria;

            IListResponse response = listHandler.Process(handler.Connection, listRequest);

            var list = rowListFactory();

            foreach (var item in response.Entities)
            {
                list.Add(item);
            }

            Target.AsObject(handler.Row, list);
        }
Ejemplo n.º 3
0
        public UpdateHandlerProxy(IDefaultHandlerFactory factory)
        {
            if (factory is null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            handler = (IUpdateHandler <TRow, TSaveRequest, TSaveResponse>)factory.CreateHandler <ISaveRequestProcessor>(typeof(TRow));
        }
Ejemplo n.º 4
0
        private object GetExistingID(IDbConnection connection, RelationInfo info,
                                     object thisKey)
        {
            var criteria = new Criteria(info.OtherKeyField.PropertyName ?? info.OtherKeyField.Name) ==
                           new ValueCriteria(thisKey);

            if (info.FilterField is object)
            {
                var flt = new Criteria(info.FilterField.PropertyName ?? info.FilterField.Name);
                if (info.FilterValue == null)
                {
                    criteria &= flt.IsNull();
                }
                else
                {
                    criteria &= flt == new ValueCriteria(info.FilterValue);
                }
            }

            var listHandler = handlerFactory.CreateHandler <IListRequestProcessor>(info.Attr.RowType);
            var listRequest = listHandler.CreateRequest();

            listRequest.ColumnSelection = ColumnSelection.KeyOnly;
            listRequest.Criteria        = criteria;

            var existing = listHandler.Process(connection, listRequest).Entities;

            if (existing.Count > 1)
            {
                throw new Exception(string.Format("Found multiple extension rows for UpdatableExtension '{0}'",
                                                  info.Attr.Alias));
            }

            if (existing.Count == 0)
            {
                return(null);
            }

            return(((IRow)existing[0]).IdField.AsObject((IRow)existing[0]));
        }
Ejemplo n.º 5
0
 public static THandler CreateHandler <THandler>(this IDefaultHandlerFactory handlerFactory, Type rowType)
 {
     return((THandler)handlerFactory.CreateHandler(rowType, typeof(THandler)));
 }