forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlUpdateGenerator.cs
More file actions
45 lines (41 loc) · 1.57 KB
/
SqlUpdateGenerator.cs
File metadata and controls
45 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#if ENTITIES
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Common.CommandTrees;
namespace Npgsql.SqlGenerators
{
class SqlUpdateGenerator : SqlBaseGenerator
{
private DbUpdateCommandTree _commandTree;
public SqlUpdateGenerator(DbUpdateCommandTree commandTree)
{
_commandTree = commandTree;
}
public override VisitedExpression Visit(DbPropertyExpression expression)
{
DbVariableReferenceExpression variable = expression.Instance as DbVariableReferenceExpression;
if (variable == null || variable.VariableName != _projectVarName.Peek())
throw new NotSupportedException();
return new PropertyExpression(expression.Property);
}
public override void BuildCommand(DbCommand command)
{
// TODO: handle _commandTree.Returning and _commandTree.Parameters
UpdateExpression update = new UpdateExpression();
_projectVarName.Push(_commandTree.Target.VariableName);
update.AppendTarget(_commandTree.Target.Expression.Accept(this));
foreach (DbSetClause clause in _commandTree.SetClauses)
{
update.AppendSet(clause.Property.Accept(this), clause.Value.Accept(this));
}
if (_commandTree.Predicate != null)
{
update.AppendWhere(_commandTree.Predicate.Accept(this));
}
_projectVarName.Pop();
command.CommandText = update.ToString();
}
}
}
#endif