Пример #1
0
        //生成更新表达式。
        private void GenerateForUpdateMembers(GenerateContext context, CommitUnitBase unit, UpdateFragment update, ISourceFragment source)
        {
            foreach (var member in unit.Members)
            {
                switch (member.ValueType)
                {
                case ECommitValueType.Constant:
                    update.SetValue(member.Metadata, source.GetMember(member.Metadata));
                    break;

                case ECommitValueType.Expression:
                    var exp = (CommitExpressionMember)member;
                    update.SetValue(member.Metadata, update.CreateExpression(exp.Expression));
                    break;
                }
            }
        }
Пример #2
0
 /// <summary>
 /// 根据属性映射表达式创建提交单元。
 /// </summary>
 /// <param name="commitUnit">当前提交单元。</param>
 /// <param name="columns">指定的列元数据集合。</param>
 /// <param name="content">属性映射表达式。</param>
 /// <returns>当前提交单元。</returns>
 protected CommitUnitBase CreateCommitUnit(CommitUnitBase commitUnit, IEnumerable <ColumnMetadata> columns, DbExpression content)
 {
     if (content is DbSelectExpression select && select.Item is DbNewExpression newExpression)
     {
         foreach (var column in columns)
         {
             var generator = GetValueGenerator(column);
             if (newExpression.Members.TryGetValue(column.Member, out DbExpression expression))
             {
                 if (expression is DbMemberExpression memberAccess && memberAccess.Member == column.Member &&
                     memberAccess.Expression == select.Source.Item)
                 {
                     commitUnit.Add(CreateCommitUnitMember(column, generator));
                 }
                 else
                 {
                     commitUnit.Add(CreateCommitUnitMember(column, generator, expression));
                 }
             }