// CRUD
        public object GetItem(IDynamicEditForm form, int id)
        {
            // ToDo: check is form overrides GetItem operation
            Type entity = form.GetEntityType();
            var  db     = GetDbContext(form);
            var  item   = db.Find(entity, id);

            return(item);
        }
        public IEnumerable <DataField> GetFormFields(IDynamicEditForm form)
        {
            var fieldSet = form.GetFields();
            var db       = GetDbContext(form);
            var pk       = db.FindPrimaryKey(form.GetEntityType()).First();
            var pkField  = fieldSet.Single(f => f.BindingProperty == pk.Name);

            pkField.PrimaryKey = true;
            pkField.PrimaryKeyGeneratedType = PrimaryKeyGeneratedTypes.OnAdd;
            return(fieldSet);
        }
        private object CreateItem()
        {
            var type = _form.GetEntityType();
            var item = Activator.CreateInstance(type);

            // Set Filter Key values
            item.SetFilterKeyValues(Fields, _serviceParameters);

            // run default validations
            _validations = _dataValidationProvider.ValidateCustomRules(_form, item, 0, Fields, FormRuleTriggers.Create);
            UpdateFieldStateValidations(_validations, 0);
            return(item);
        }
        public IEnumerable <DataField> GetFormFields(IDynamicEditForm form)
        {
            var fieldSet = form.GetFields();

            using (var db = GetDbContext(form))
            {
                var pk      = db.FindSinglePrimaryKeyProperty(form.GetEntityType());
                var pkField = fieldSet.Single(f => f.BindingProperty == pk.Name);
                pkField.PrimaryKey = true;
                pkField.PrimaryKeyGeneratedType = (PrimaryKeyGeneratedTypes)pk.ValueGenerated;
            }

            return(fieldSet);
        }