Esempio n. 1
0
        public ICondition Or(ICondition conditionExpression)
        {
            ConditionExpressionCollection cs = new ConditionExpressionCollection();

            cs.ConditionRelation = ConditionRelation.Or;
            cs.Add(this);
            if (conditionExpression is IConditionExpression)
            {
                cs.Add(conditionExpression);
            }
            else
            {
                IConditionExpressionCollection conditionCollection = (IConditionExpressionCollection)conditionExpression;
                if (conditionCollection.ConditionRelation == ConditionRelation.Or)
                {
                    foreach (ICondition item in conditionCollection)
                    {
                        cs.Add(item);
                    }
                }
                else
                {
                    cs.Add(conditionCollection);
                }
            }
            return(cs);
        }
Esempio n. 2
0
        public int Delete(object entity)
        {
            object entityType = MappingProvider.GetEntityTypeByInstance(entity);
            ConditionExpressionCollection cs = CreateConditionByKeyColumn(entity);

            return(SqlProvider.Delete(this, MappingProvider, null, entityType, cs));
        }
Esempio n. 3
0
        public int Update(object entity, params object[] updateProperties)
        {
            object entityType = MappingProvider.GetEntityTypeByInstance(entity);

            ITable table = MappingProvider.GetTable(entityType);
            IDictionary <string, object> nameValues;

            if (updateProperties == null || updateProperties.Length == 0)
            {
                //说明是更新所有列
                nameValues = ObjectAccessor.ToPropertySets(MappingProvider, entityType, entity, Util.CollectNames(table.NonPrimaryKeyProperties));
            }
            else
            {
                //说明是更新指定列
                nameValues = ObjectAccessor.ToPropertySets(MappingProvider, entityType, entity, Util.CollectNames(updateProperties), table.PrimaryProperties);
            }
            if (nameValues.Count <= 0)
            {
                return(0);
            }
            ConditionExpressionCollection cs = CreateConditionByKeyColumn(entity);

            return(SqlProvider.Update(this, MappingProvider, null, entityType, cs, nameValues));
        }
Esempio n. 4
0
        private IConditionExpressionCollection Copy()
        {
            ConditionExpressionCollection cs = new ConditionExpressionCollection(Items.Count);

            cs.ConditionRelation = ConditionRelation;
            foreach (ICondition conditionExpression in this)
            {
                cs.Add(conditionExpression);
            }
            return(cs);
        }
Esempio n. 5
0
        private ConditionExpressionCollection CreateConditionByKeyColumn(object entity)
        {
            //if (obj == null) throw ExceptionFactory.EntityNullException("obj");
            ConditionExpressionCollection cs = new ConditionExpressionCollection();


            object entityType = MappingProvider.GetEntityTypeByInstance(entity);
            var    table      = MappingProvider.GetTable(entityType);

            foreach (string property in table.PrimaryProperties)
            {
                cs.Add(new ConditionExpression(property, ConditionOperator.Equal, ObjectAccessor.Get(entity, property)));
            }
            return(cs);
        }