当前位置: 首页>>代码示例>>C#>>正文


C# SqlQuery.AddParam方法代码示例

本文整理汇总了C#中Serenity.Data.SqlQuery.AddParam方法的典型用法代码示例。如果您正苦于以下问题:C# SqlQuery.AddParam方法的具体用法?C# SqlQuery.AddParam怎么用?C# SqlQuery.AddParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Serenity.Data.SqlQuery的用法示例。


在下文中一共展示了SqlQuery.AddParam方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Clone

        /// <summary>
        /// Creates a clone of the query.
        /// </summary>
        /// <returns>A cloned query.</returns>
        /// <remarks>
        /// Clones states like TrackAssignments, AssignedFields etc,
        /// creates a copy of Params dictionary
        /// </remarks>
        public SqlQuery Clone()
        {
            var clone = new SqlQuery();

            clone.dialect = dialect;
            clone.dialectOverridden = dialectOverridden;
            clone.skip = skip;
            clone.take = take;
            clone.countRecords = countRecords;

            clone.into = new List<object>(into);
            clone.intoIndex = intoIndex;

            Column s;
            for (int i = 0; i < columns.Count; i++)
            {
                s = columns[i];
                var si = new Column(s.Expression, s.ColumnName, s.IntoRowIndex, s.IntoField);
                clone.columns.Add(si);
            }

            clone.from = new StringBuilder(from.ToString());
            if (where != null)
                clone.where = new StringBuilder(where.ToString());

            if (orderBy != null)
            {
                clone.orderBy = new List<string>();
                clone.orderBy.AddRange(orderBy);
            }

            if (groupBy != null)
                clone.groupBy = new StringBuilder(groupBy.ToString());

            if (having != null)
                clone.having = new StringBuilder(having.ToString());

            if (parent != null)
                clone.parent = this.parent;
            else if (this.Params != null)
                foreach (var pair in this.Params)
                    clone.AddParam(pair.Key, pair.Value);

            return clone;
        }
开发者ID:volkanceylan,项目名称:Serenity,代码行数:53,代码来源:SqlQuery_Clone.cs

示例2: List

        public static AuditLogListResponse List(string schema, AuditLogListRequest request)
        {
#if COREFX
            var fld = Dependency.Resolve<IAuditLogRow>();
#else
            var fld = Dependency.Resolve<IAuditLogRow>(schema);
#endif

            Authorization.ValidateLoggedIn();

            var response = new AuditLogListResponse();

            using (var connection = SqlConnections.NewByKey("Default"))
            {
                response.Entities = new List<Row>();

                var row = ((Row)fld).CreateNew();

                if (request.Sort == null ||
                    request.Sort.Length == 0)
                    request.Sort = new SortBy[] { new SortBy(fld.DateField.Name, true) };

                var query = new SqlQuery().From(row)
                    .Select(
                        (Field)fld.IdField,
                        fld.EntityTypeIdField,
                        fld.EntityIdField,
                        fld.ParentTypeIdField,
                        fld.OldParentIdField,
                        fld.NewParentIdField,
                        fld.DateField,
                        (Field)fld.UserIdField,
                        fld.AuditTypeIdField,
                        fld.OldAuditDataField,
                        fld.NewAuditDataField)
                    .OrderBy(
                        (Field)fld.IdField)
                    .ApplySkipTakeAndCount(request.Skip, request.Take, request.ExcludeTotalCount)
                    .ApplySort(request.Sort);

                if (request.EntityTypeId != null &&
                    request.EntityId != null)
                {
                    var pEntityId = query.AddParam(request.EntityId);
                    var pEntityTypeId = query.AddParam(request.EntityTypeId);

                    query.Where(~(
                        ~(
                            new Criteria(0, fld.EntityTypeIdField) == pEntityTypeId &
                            new Criteria(0, fld.EntityIdField) == pEntityId) |
                        ~(
                            new Criteria(0, fld.ParentTypeIdField) == pEntityTypeId &
                            ~(
                                new Criteria(0, fld.OldParentIdField) == pEntityId |
                                new Criteria(0, fld.NewParentIdField) == pEntityId))));
                }
                else
                {
                    if (request.EntityTypeId != null)
                        query.WhereEqual(fld.EntityTypeIdField, request.EntityTypeId);//Convert.ToInt32(request.EntityTypeId.Value));

                    if (request.EntityId != null)
                        query.WhereEqual(fld.EntityIdField, request.EntityId.Value);
                }

                response.TotalCount = query.ForEach(connection, delegate()
                {
                    response.Entities.Add(row.Clone());
                });

                response.SetSkipTakeTotal(query);

                response.IdNameLookups = new Dictionary<EntityType, Dictionary<long, string>>();
                response.FieldTitles = new Dictionary<EntityType, Dictionary<string, string>>();
                response.ForeignEntityTypes = new Dictionary<EntityType, Dictionary<string, string>>();
                response.EntityTitles = new Dictionary<EntityType, string>();

                var lookups = response.IdNameLookups;
                var titles = response.FieldTitles;
                var foreigns = response.ForeignEntityTypes;
                var entities = response.EntityTitles;

                Action<EntityType, Int64> addLookup = (entityType, id) => {

                    Dictionary<long, string> lookup;
                    if (!lookups.TryGetValue(entityType, out lookup))
                    {
                        lookup = new Dictionary<long, string>();
                        lookups[entityType] = lookup;
                    }

                    if (!lookup.ContainsKey(id))
                        lookup[id] = null;
                };

                Action<EntityType, string> addTitle = (entityType, field) =>
                {

                    Dictionary<string, string> lookup;
                    if (!titles.TryGetValue(entityType, out lookup))
//.........这里部分代码省略.........
开发者ID:volkanceylan,项目名称:Serenity,代码行数:101,代码来源:AuditLogService.cs


注:本文中的Serenity.Data.SqlQuery.AddParam方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。