本文整理汇总了C#中SelectQuery类的典型用法代码示例。如果您正苦于以下问题:C# SelectQuery类的具体用法?C# SelectQuery怎么用?C# SelectQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SelectQuery类属于命名空间,在下文中一共展示了SelectQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Finalize
public override SelectQuery Finalize(SelectQuery selectQuery)
{
selectQuery = base.Finalize(selectQuery);
new QueryVisitor().Visit(selectQuery.Select, element =>
{
if (element.ElementType == QueryElementType.SqlParameter)
{
((SqlParameter)element).IsQueryParameter = false;
selectQuery.IsParameterDependent = true;
}
});
switch (selectQuery.QueryType)
{
case QueryType.Delete :
selectQuery = GetAlternativeDelete(selectQuery);
selectQuery.From.Tables[0].Alias = "$";
break;
case QueryType.Update :
selectQuery = GetAlternativeUpdate(selectQuery);
break;
}
return selectQuery;
}
示例2: Finalize
public override SelectQuery Finalize(SelectQuery selectQuery)
{
CheckAliases(selectQuery, int.MaxValue);
new QueryVisitor().VisitParentFirst(selectQuery, SearchSelectClause);
if (selectQuery.QueryType == QueryType.InsertOrUpdate)
{
foreach (var key in selectQuery.Insert.Items)
new QueryVisitor().Visit(key.Expression, SetNonQueryParameter);
foreach (var key in selectQuery.Update.Items)
new QueryVisitor().Visit(key.Expression, SetNonQueryParameter);
foreach (var key in selectQuery.Update.Keys)
new QueryVisitor().Visit(key.Expression, SetNonQueryParameter);
}
selectQuery = base.Finalize(selectQuery);
switch (selectQuery.QueryType)
{
case QueryType.Delete : return GetAlternativeDelete(selectQuery);
case QueryType.Update : return GetAlternativeUpdate(selectQuery);
default : return selectQuery;
}
}
示例3: BuildSql
protected override void BuildSql(int commandNumber, SelectQuery selectQuery, StringBuilder sb, int indent, bool skipAlias)
{
SelectQuery = selectQuery;
StringBuilder = sb;
Indent = indent;
SkipAlias = skipAlias;
if (_identityField != null)
{
indent += 2;
AppendIndent().AppendLine("SELECT");
AppendIndent().Append("\t");
BuildExpression(_identityField, false, true);
sb.AppendLine();
AppendIndent().AppendLine("FROM");
AppendIndent().AppendLine("\tNEW TABLE");
AppendIndent().AppendLine("\t(");
}
base.BuildSql(commandNumber, selectQuery, sb, indent, skipAlias);
if (_identityField != null)
sb.AppendLine("\t)");
}
示例4: RenderSelect
private string RenderSelect(SelectQuery query, bool renderOrderBy)
{
query.Validate();
StringBuilder selectBuilder = new StringBuilder();
//Start the select statement
Select(selectBuilder, query.Distinct);
//Render Top clause
if (query.Top > -1)
{
selectBuilder.AppendFormat("top {0} ", query.Top);
}
//Render select columns
SelectColumns(selectBuilder, query.Columns);
FromClause(selectBuilder, query.FromClause, query.TableSpace);
Where(selectBuilder, query.WherePhrase);
WhereClause(selectBuilder, query.WherePhrase);
if (renderOrderBy)
{
OrderBy(selectBuilder, query.OrderByTerms);
OrderByTerms(selectBuilder, query.OrderByTerms);
}
return selectBuilder.ToString();
}
示例5: RenderSelect
private string RenderSelect(SelectQuery query, bool forRowCount, int offset, int limitRows)
{
query.Validate();
StringBuilder selectBuilder = new StringBuilder();
//Start the select statement
Select(selectBuilder, query.Distinct);
//Render select columns
if (forRowCount)
{
SelectColumn(selectBuilder, new SelectColumn("*", null, "cnt", SqlAggregationFunction.Count));
}
else
{
SelectColumns(selectBuilder, query.Columns);
}
FromClause(selectBuilder, query.FromClause, query.TableSpace);
Where(selectBuilder, query.WherePhrase);
WhereClause(selectBuilder, query.WherePhrase);
OrderBy(selectBuilder, query.OrderByTerms);
OrderByTerms(selectBuilder, query.OrderByTerms);
if (limitRows > -1)
{
selectBuilder.AppendFormat(" limit {0}, {1}", offset, limitRows);
}
return selectBuilder.ToString();
}
示例6: Execute
public string Execute(string itemID, string srlnCode)
{
string retVal = String.Empty;
var qry = new SelectQuery();
var srln = FromTerm.Table("GXSERIALNUMBER", "srnl");
qry.FromClause.BaseTable =srln;
qry.Columns.Add(new SelectColumn("GXID", srln));
qry.WherePhrase.Terms.Add(WhereTerm.CreateCompare(
SqlExpression.Field("GXITEMID", srln),
SqlExpression.Parameter("@itemID"),
CompareOperator.Equal));
qry.WherePhrase.Terms.Add(WhereTerm.CreateCompare(
SqlExpression.Field("GXCODE"),
SqlExpression.Parameter("@srlnCode"),
CompareOperator.Equal));
var dataAccess = AppContext.ServiceLocator.GetService<IslDataAccessDbProvider>();
string sqlText = slRendererFactory.GetRenderer(dataAccess.Info.DBProviderName).RenderSelect(qry);
slQueryParameters qryParams = new slQueryParameters();
qryParams.Add("@itemID", itemID);
qryParams.Add("@srlnCode", srlnCode);
object res = dataAccess.ExecuteScalar(sqlText, qryParams);
if (res != null && res != DBNull.Value)
retVal = Convert.ToString(res);
return retVal;
}
示例7: BuildSql
protected override void BuildSql(int commandNumber, SelectQuery selectQuery, StringBuilder sb, int indent, bool skipAlias)
{
base.BuildSql(commandNumber, selectQuery, sb, indent, skipAlias);
sb
.Replace("NULL IS NOT NULL", "1=0")
.Replace("NULL IS NULL", "1=1");
}
示例8: GenerateSingleMapper
private static Delegate GenerateSingleMapper() {
var config = new CustomConfig();
var selectQuery = new SelectQuery<Post>(new Mock<ISelectQueryExecutor>().Object).Fetch(p => p.Blog) as SelectQuery<Post>;
var writer = new SelectWriter(new SqlServer2012Dialect(), config);
var result = writer.GenerateSql(selectQuery);
var mapper = new NonCollectionMapperGenerator(config);
var func = mapper.GenerateNonCollectionMapper<Post>(result.FetchTree);
return func.Item1;
}
示例9: Finalize
public override SelectQuery Finalize(SelectQuery selectQuery)
{
selectQuery = base.Finalize(selectQuery);
switch (selectQuery.QueryType)
{
case QueryType.Delete : return GetAlternativeDelete(selectQuery);
default : return selectQuery;
}
}
示例10: ShouldCreateAndWhereQuery
public void ShouldCreateAndWhereQuery()
{
var query =
new SelectQuery<Model.Model>().Select("Id")
.Where("Id", new IsNotNull<int>())
.AndWhere("Id", new IsNull<int>())
.ToString();
query.Should().Be("SELECT [Id] FROM [Model] WHERE ([Id] IS NOT NULL AND [Id] IS NULL)");
}
示例11: CommandCount
public override int CommandCount(SelectQuery selectQuery)
{
if (Version == DB2Version.LUW && selectQuery.IsInsert && selectQuery.Insert.WithIdentity)
{
_identityField = selectQuery.Insert.Into.GetIdentityField();
if (_identityField == null)
return 2;
}
return 1;
}
示例12: CommandCount
public override int CommandCount(SelectQuery selectQuery)
{
if (selectQuery.IsCreateTable)
{
_identityField = selectQuery.CreateTable.Table.Fields.Values.FirstOrDefault(f => f.IsIdentity);
if (_identityField != null)
return 3;
}
return base.CommandCount(selectQuery);
}
示例13: Finalize
public override SelectQuery Finalize(SelectQuery selectQuery)
{
CheckAliases(selectQuery, int.MaxValue);
selectQuery = base.Finalize(selectQuery);
switch (selectQuery.QueryType)
{
case QueryType.Delete : return GetAlternativeDelete(selectQuery);
case QueryType.Update : return GetAlternativeUpdate(selectQuery);
default : return selectQuery;
}
}
示例14: Finalize
public override SelectQuery Finalize(SelectQuery selectQuery)
{
new QueryVisitor().Visit(selectQuery.Select, SetQueryParameter);
selectQuery = base.Finalize(selectQuery);
switch (selectQuery.QueryType)
{
case QueryType.Delete : return GetAlternativeDelete(selectQuery);
case QueryType.Update : return GetAlternativeUpdate(selectQuery);
default : return selectQuery;
}
}
示例15: ProcessQuery
protected override SelectQuery ProcessQuery(SelectQuery selectQuery)
{
if (selectQuery.IsInsert && selectQuery.Insert.Into.Name == "Parent")
{
var expr =
new QueryVisitor().Find(selectQuery.Insert, e =>
{
if (e.ElementType == QueryElementType.SetExpression)
{
var se = (SelectQuery.SetExpression)e;
return ((SqlField)se.Column).Name == "ParentID";
}
return false;
}) as SelectQuery.SetExpression;
if (expr != null)
{
var value = ConvertTo<int>.From(((IValueContainer)expr.Expression).Value);
if (value == 555)
{
var tableName = "Parent1";
var dic = new Dictionary<IQueryElement,IQueryElement>();
selectQuery = new QueryVisitor().Convert(selectQuery, e =>
{
if (e.ElementType == QueryElementType.SqlTable)
{
var oldTable = (SqlTable)e;
if (oldTable.Name == "Parent")
{
var newTable = new SqlTable(oldTable) { Name = tableName, PhysicalName = tableName };
foreach (var field in oldTable.Fields.Values)
dic.Add(field, newTable.Fields[field.Name]);
return newTable;
}
}
IQueryElement ex;
return dic.TryGetValue(e, out ex) ? ex : null;
});
}
}
}
return selectQuery;
}