ISqlBuilderCache.Set(string sqlBuilderName, ISqlBuilder sqlBuilder, bool readOnly = true) Method
.NET Standard 2.x
Caches an ISqlBuilder object in the ISqlBuilderCache object and specifies a cache name for the ISqlBuilder object. You can also specify whether the ISqlBuilder object is read-only when it is obtained from the cache; by default it is read-only.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
void Set(string sqlBuilderName, ISqlBuilder sqlBuilder, bool readOnly = true);
Parameters
sqlBuilderName System.String
The name for the ISqlBuilder when it is cached.
sqlBuilder SnapObjects.Data.ISqlBuilder
The ISqlBuilder object to be cached in the ISqlBuilderCache object.
readOnly System.Boolean
Specifies whether the ISqlBuilder object is read-only when it is obtained from the cache.
True (default): you can only use the Get method to get an ISqlReadOnlyBuilder object from the cache.
False: you can use the Get method to get an ISqlReadOnlyBuilder object from the cache or use the GetModifiable method to get a TSqlBuilder object.
Examples
The following code example saves the ISqlBuilder object to ISqlBuilderCache, and specifies a cache name for it.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlBuilderCacheExamples
{
public class SetExample
{
private readonly SchoolContext _context;
public SetExample(SchoolContext context)
{
_context = context;
}
public void Example()
{
// Creates a SqlQueryBuilder object.
var build = SqlBuilderFactory.Create<ISqlQueryBuilder>("original sql");
build.Select("select Title from Course where CourseID = 1050");
// Generates a SqlBuilderCache object via SqlBuilderFactory.Cache.
var cache = SqlBuilderFactory.Cache;
// Injects SqlQueryBuilder to the SqlBuilderCache object.
cache.Set("querySql", build, true);
// Gets the ISqlReadOnlyBuilder object whose name is "querySql".
var get = cache.Get("querySql");
Console.WriteLine("SqlBuilder Name = {0}", get.Name);
/*This code produces the following output:
SqlBuilder Name = original sql
*/
}
}
}
Applies to
.NET Standard
2.x