本文整理汇总了C#中ScrewTurn.Wiki.Plugins.SqlCommon.QueryBuilder.OrWhere方法的典型用法代码示例。如果您正苦于以下问题:C# QueryBuilder.OrWhere方法的具体用法?C# QueryBuilder.OrWhere怎么用?C# QueryBuilder.OrWhere使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScrewTurn.Wiki.Plugins.SqlCommon.QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder.OrWhere方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNamespace
/// <summary>
/// Gets a namespace.
/// </summary>
/// <param name="connection">A database connection.</param>
/// <param name="name">The name of the namespace (cannot be <c>null</c> or empty).</param>
/// <returns>The <see cref="T:NamespaceInfo" />, or <c>null</c> if no namespace is found.</returns>
private NamespaceInfo GetNamespace(DbConnection connection, string name)
{
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
// select ... from Namespace left join Page on Namespace.DefaultPage = Page.Name where Namespace.Name = <name> and (Namespace.DefaultPage is null or Page.Namespace = <name>)
string query = queryBuilder.SelectFrom("Namespace", "Page", "DefaultPage", "Name", Join.LeftJoin, new string[] { "Name", "DefaultPage" }, new string[] { "CreationDateTime" });
query = queryBuilder.Where(query, "Namespace", "Name", WhereOperator.Equals, "Name1");
query = queryBuilder.AndWhere(query, "Namespace", "DefaultPage", WhereOperator.IsNull, null, true, false);
query = queryBuilder.OrWhere(query, "Page", "Namespace", WhereOperator.Equals, "Name2", false, true);
List<Parameter> parameters = new List<Parameter>(2);
parameters.Add(new Parameter(ParameterType.String, "Name1", name));
parameters.Add(new Parameter(ParameterType.String, "Name2", name));
DbCommand command = builder.GetCommand(connection, query, parameters);
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
NamespaceInfo result = null;
if(reader.Read()) {
string realName = reader["Namespace_Name"] as string;
string page = GetNullableColumn<string>(reader, "Namespace_DefaultPage", null);
PageInfo defaultPage = string.IsNullOrEmpty(page) ? null :
new PageInfo(NameTools.GetFullName(realName, page), this, (DateTime)reader["Page_CreationDateTime"]);
result = new NamespaceInfo(realName, this, defaultPage);
}
CloseReader(reader);
return result;
}
else return null;
}
示例2: GetNamespaces
/// <summary>
/// Gets all the sub-namespaces.
/// </summary>
/// <returns>The sub-namespaces, sorted by name.</returns>
public NamespaceInfo[] GetNamespaces()
{
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
// select ... from Namespace left join Page on Namespace.DefaultPage = Page.Name where Namespace.Name <> '' and (Namespace.DefaultPage is null or Page.Namespace <> '')
string query = queryBuilder.SelectFrom("Namespace", "Page", "DefaultPage", "Name", Join.LeftJoin, new string[] { "Name", "DefaultPage" }, new string[] { "CreationDateTime" });
query = queryBuilder.Where(query, "Namespace", "Name", WhereOperator.NotEquals, "Empty1");
query = queryBuilder.AndWhere(query, "Namespace", "DefaultPage", WhereOperator.IsNull, null, true, false);
query = queryBuilder.OrWhere(query, "Page", "Namespace", WhereOperator.NotEquals, "Empty2", false, true);
query = queryBuilder.OrderBy(query, new[] { "Namespace_Name" }, new[] { Ordering.Asc });
List<Parameter> parameters = new List<Parameter>(2);
parameters.Add(new Parameter(ParameterType.String, "Empty1", ""));
parameters.Add(new Parameter(ParameterType.String, "Empty2", ""));
DbCommand command = builder.GetCommand(connString, query, parameters);
DbDataReader reader = ExecuteReader(command);
if(reader != null) {
List<NamespaceInfo> result = new List<NamespaceInfo>(10);
while(reader.Read()) {
string realName = reader["Namespace_Name"] as string;
string page = GetNullableColumn<string>(reader, "Namespace_DefaultPage", null);
PageInfo defaultPage = string.IsNullOrEmpty(page) ? null :
new PageInfo(NameTools.GetFullName(realName, page), this, (DateTime)reader["Page_CreationDateTime"]);
// The query returns duplicate entries if the main page of two or more namespaces have the same name
if(result.Find(n => { return n.Name.Equals(realName); }) == null) {
result.Add(new NamespaceInfo(realName, this, defaultPage));
}
}
CloseReader(command, reader);
return result.ToArray();
}
else return null;
}
示例3: DeleteOutgoingLinks
/// <summary>
/// Deletes the outgoing links of a page and all the target links that include the page.
/// </summary>
/// <param name="page">The full name of the page.</param>
/// <returns><c>true</c> if the links are deleted, <c>false</c> otherwise.</returns>
/// <exception cref="ArgumentNullException">If <b>page</b> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">If <b>page</b> is empty.</exception>
public bool DeleteOutgoingLinks(string page)
{
if(page == null) throw new ArgumentNullException("page");
if(page.Length == 0) throw new ArgumentException("Page cannot be empty", "page");
ICommandBuilder builder = GetCommandBuilder();
QueryBuilder queryBuilder = new QueryBuilder(builder);
string query = queryBuilder.DeleteFrom("OutgoingLink");
query = queryBuilder.Where(query, "Source", WhereOperator.Equals, "Source");
query = queryBuilder.OrWhere(query, "Destination", WhereOperator.Equals, "Destination");
List<Parameter> parameters = new List<Parameter>(2);
parameters.Add(new Parameter(ParameterType.String, "Source", page));
parameters.Add(new Parameter(ParameterType.String, "Destination", page));
DbCommand command = builder.GetCommand(connString, query, parameters);
int rows = ExecuteNonQuery(command);
return rows > 0;
}