ISqlUpdateBuilder.Set(string columnName, string clause) Method
.NET Standard 2.x
Specifies the value of a column to be updated with a raw SQL.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlUpdateBuilder Set(string columnName, string clause);
Parameters
columnName
System.String
The name of the column to be updated.
clause
System.String
A string of raw SQL which is to be updated to the column.
Returns
SnapObjects.Data.ISqlUpdateBuilder
Returns the current ISqlUpdateBuilder
object.
Examples
The following code example demonstrates how to use the Set(string columnName, string clause) method.It modifies the value of the "Name" column for the record whose DepartmentID=1 in the "Department" table using the value returned by a raw SQL string.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlUpdateBuilderExamples
{
public class SetExample
{
private SchoolContext _context;
public SetExample(SchoolContext dataContext)
{
// Sets Data Context.
_context = dataContext;
}
public void Example2()
{
// Declares SqlQueryBuilder
var sqlbuilder = new SqlUpdateBuilder();
// Updates the record whose DepartmentID=1 in the "Department" table.
// Modifies the Name value with the value returned by a raw SQL string.
sqlbuilder.Update("Department")
.Set("Name", "select name from Department where DepartmentID=2")
.Where("DepartmentID", "1");
// Converts to raw SQL for the database corresponding to the data context.
string sql = sqlbuilder.ToSqlString(_context);
Console.WriteLine(sql);
/*This code produces the following output:
UPDATE [Department] SET [Name] = 'Chinese'
WHERE ([DepartmentID] = 1)
*/
}
}
}
Applies to
.NET Standard
2.x