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


C# SqlQuery.Delete方法代码示例

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


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

示例1: databaseWork

    void databaseWork()
    {
        int rows = 100;

        // create table
        string tableName = Guid.NewGuid().ToString().Replace("-", "");
        var fields = new DataValueType[] { DataValueType.IntegerType, DataValueType.DateTimeType, DataValueType.ShortStringType, DataValueType.LongStringType };
        var createActions = new List<DbAction>();
        createActions.Add(DbAction.EnsureTable(tableName, new string[] { "id" }, new DataValueType[] { DataValueType.IntegerType }));
        createActions.Add(DbAction.AddField(tableName, "f1", DataValueType.BooleanType, true, new BooleanDataValue(false)));
        createActions.Add(DbAction.AddField(tableName, "f2", DataValueType.DateTimeType, false, new DateTimeDataValue(DateTime.Now)));
        createActions.Add(DbAction.AddField(tableName, "f3", DataValueType.FloatType, false, new FloatDataValue(0)));
        createActions.Add(DbAction.AddField(tableName, "f4", DataValueType.ShortStringType, true, new ShortStringDataValue("test")));
        createActions.Add(DbAction.AddField(tableName, "f5", DataValueType.LongStringType, false, new LongStringDataValue("test")));
        WAFRuntime.Engine.Dao.DbProvider.UpdateDatabase(createActions);

        // inserting records
        var table = new SqlTable(tableName);
        var id = new SqlFieldInteger("id", table);
        var f1 = new SqlFieldBoolean("f1", table);
        var f2 = new SqlFieldDateTime("f2", table);
        var f3 = new SqlFieldFloat("f3", table);
        var f4 = new SqlFieldShortString("f4", table);
        var f5 = new SqlFieldLongString("f5", table);
        {
            for (int r = 0; r < rows; r++) {
                SqlQuery q = new SqlQuery(WAFRuntime.Engine.Dao);
                q.Insert(table);
                q.Values(id, r);
                q.Values(f1, false);
                q.Values(f2, DateTime.Now);
                q.Values(f3, (double)r);
                q.Values(f4, "My test string " + r);
                q.Values(f5, "My long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long test string " + r);
                q.ExecuteNonQuery();
            }
        }
        {
            // quering 10 records at the time
            for (int r = 0; r < rows; r++) {
                SqlQuery q = new SqlQuery(WAFRuntime.Engine.Dao);
                q.From(table);
                q.Select(f1);
                q.Select(f2);
                q.Select(f3);
                q.Select(f4);
                q.Where(id > r);
                using (var dr = q.ExecuteReader()) {
                    while (dr.Read()) { }
                }
            }
        }

        // deleting 1/10 of the records
        for (int r = 0; r < rows / 10; r++) {
            SqlQuery q = new SqlQuery(WAFRuntime.Engine.Dao);
            q.Delete(table);
            q.Where(id == r);
            q.ExecuteNonQuery();
        }

        // dropping table
        WAFRuntime.Engine.Dao.DbProvider.UpdateDatabase(new DbAction[] { DbAction.DeleteTable(tableName) }.ToList());
    }
开发者ID:kyvkri,项目名称:MG,代码行数:64,代码来源:Default.aspx.cs

示例2: RemoveJournalItem

        public void RemoveJournalItem()
        {
            if (CanRemoveItem && null != selectedItem &&
                MessageBox.Show(string.Format("Ви впевнені що хочете вилучити позицію \"{0}\"?",selectedItem.Name), "вилучення", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                using (DbManager db = new DbManager())
                {
                    db.BeginTransaction();
                    try
                    {
                        if (selectedItem.Tovar != null && !selectedItem.IsRent)
                        {
                            //add ostatok in tovar
                            selectedItem.Tovar.Ostatok += (int)selectedItem.Amount;
                            SqlQuery<Tovar> query2 = new SqlQuery<Tovar>(db);
                            query2.Update(selectedItem.Tovar);
                        }
                        //insert new journal item
                        SqlQuery<Journal> query = new SqlQuery<Journal>(db);
                        query.Delete(selectedItem);
                        db.CommitTransaction();
                    }
                    catch
                    {
                        db.RollbackTransaction();
                        throw;
                    }

                }
                PropertyChange("JournalList");
                PropertyChange("DaySum");
                PropertyChange("InKasaSum");
            }
        }
开发者ID:vhytyk,项目名称:boginya-journal,代码行数:34,代码来源:JournalView.xaml.cs

示例3: deleteUnusedNodeIdsIn_RelationTable

    void deleteUnusedNodeIdsIn_RelationTable(int relationId, HashSet<int> legalNodeIds)
    {
        var rel = Engine.Definition.Relation[relationId];
        var table = new SqlTable(rel.TableName);
        var nodeIdField1 = new SqlFieldInteger(rel.NameParents, table);
        var nodeIdField2 = new SqlFieldInteger(rel.NameChildren, table);

        var illegalNodeIds = new HashSet<int>();
        {
            var q = new SqlQuery(Engine.Dao);
            q.From(table);
            var rNodeId1 = q.Select(nodeIdField1);
            var rNodeId2 = q.Select(nodeIdField2);
            using (var rs = q.ExecuteReader()) {
                while (rs.Read()) {
                    if (Info.BreakExecution) return;
                    if (!legalNodeIds.Contains(rNodeId1.Value) && !illegalNodeIds.Contains(rNodeId1.Value)) illegalNodeIds.Add(rNodeId1.Value);
                    if (!legalNodeIds.Contains(rNodeId2.Value) && !illegalNodeIds.Contains(rNodeId2.Value)) illegalNodeIds.Add(rNodeId2.Value);
                }
            }
        }
        {
            foreach (var nodeId in illegalNodeIds) {
                if (Info.BreakExecution) return;
                addDeleteCount();
                if (_delete) {
                    var q = new SqlQuery(Engine.Dao);
                    q.Delete(table);
                    q.Where(nodeIdField1 == nodeId | nodeIdField2 == nodeId);
                    q.ExecuteNonQuery();
                }
            }
        }
    }
开发者ID:kyvkri,项目名称:mgone,代码行数:34,代码来源:Default.aspx.cs

示例4: deleteUnusedNodeIdsIn_NodeCsd

 void deleteUnusedNodeIdsIn_NodeCsd(HashSet<int> legalNodeIds)
 {
     var illegalNodeIds = new HashSet<int>();
     {
         var q = new SqlQuery(Engine.Dao);
         q.From(Sql.Table.NodeCsd);
         var rNodeId = q.Select(Sql.Field.NodeCsd.NodeId);
         using (var rs = q.ExecuteReader()) {
             while (rs.Read()) {
                 if (Info.BreakExecution) return;
                 if (!legalNodeIds.Contains(rNodeId.Value) && !illegalNodeIds.Contains(rNodeId.Value)) illegalNodeIds.Add(rNodeId.Value);
             }
         }
     }
     {
         foreach (var nodeId in illegalNodeIds) {
             if (Info.BreakExecution) return;
             addDeleteCount();
             if (_delete) {
                 var q = new SqlQuery(Engine.Dao);
                 q.Delete(Sql.Table.NodeCsd);
                 q.Where(Sql.Field.NodeCsd.NodeId == nodeId);
                 q.ExecuteNonQuery();
             }
         }
     }
 }
开发者ID:kyvkri,项目名称:mgone,代码行数:27,代码来源:Default.aspx.cs

示例5: deleteUnusedLanguagesIn_NodeCsd

 void deleteUnusedLanguagesIn_NodeCsd(List<int> legalCultures)
 {
     var lcids = new List<int>();
     var nodeIds = new List<int>();
     {
         var q = new SqlQuery(Engine.Dao);
         q.From(Sql.Table.NodeCsd);
         var rNodeId = q.Select(Sql.Field.NodeCsd.NodeId);
         var rLCID = q.Select(Sql.Field.NodeCsd.LCID);
         q.Where(!Sql.In(Sql.Field.NodeCsd.LCID, legalCultures));
         using (var rs = q.ExecuteReader()) {
             while (rs.Read()) {
                 if (Info.BreakExecution) return;
                 nodeIds.Add(rNodeId.Value);
                 lcids.Add(rLCID.Value);
             }
         }
     }
     {
         for (int i = 0; i < nodeIds.Count; i++) {
             if (Info.BreakExecution) return;
             addDeleteCount();
             if (_delete) {
                 var q = new SqlQuery(Engine.Dao);
                 q.Delete(Sql.Table.NodeCsd);
                 q.Where(Sql.Field.NodeCsd.NodeId == nodeIds[i] & Sql.Field.NodeCsd.LCID == lcids[i]);
                 q.ExecuteNonQuery();
             }
         }
     }
 }
开发者ID:kyvkri,项目名称:mgone,代码行数:31,代码来源:Default.aspx.cs

示例6: deleteUnusedIRelRecords

    void deleteUnusedIRelRecords(HashSet<int> allContentIdInClassTables)
    {
        foreach (var propDef in Engine.Definition.Property.Values.Where(p =>
            p.BasePropertyClassId == PropertyBaseClass.FileFolderProperty
            || p.BasePropertyClassId == PropertyBaseClass.InnerContents)) {

            var illegalContentId = new HashSet<int>();
            var illegalParentContentId = new HashSet<int>();

            {
                var q = new SqlQuery(Engine.Dao);
                var table = new SqlTable(propDef.GetInnerContentTableName());
                q.From(table);
                var rParentContentId = q.Select(new SqlFieldInteger("parent_content_id", table));
                var rContentId = q.Select(new SqlFieldInteger("content_id", table));
                using (var rs = q.ExecuteReader()) {
                    while (rs.Read()) {
                        if (Info.BreakExecution) return;
                        if (!allContentIdInClassTables.Contains(rContentId.Value)) {
                            if (!illegalContentId.Contains(rContentId.Value)) {
                                illegalContentId.Add(rContentId.Value);
                            }
                        }
                        if (!allContentIdInClassTables.Contains(rParentContentId.Value)) {
                            if (!illegalParentContentId.Contains(rParentContentId.Value)) {
                                illegalParentContentId.Add(rParentContentId.Value);
                            }
                        }
                    }
                }
            }

            {
                foreach (var contentId in illegalContentId) {
                    if (Info.BreakExecution) return;
                    addDeleteCount();
                    if (_delete) {
                        var q = new SqlQuery(Engine.Dao);
                        var table = new SqlTable(propDef.GetInnerContentTableName());
                        q.Delete(table);
                        q.Where(new SqlFieldInteger("content_id", table) == contentId);
                        q.ExecuteNonQuery();
                    }
                }
                foreach (var parentContentId in illegalParentContentId) {
                    if (Info.BreakExecution) return;
                    addDeleteCount();
                    if (_delete) {
                        var q = new SqlQuery(Engine.Dao);
                        var table = new SqlTable(propDef.GetInnerContentTableName());
                        q.Delete(table);
                        q.Where(new SqlFieldInteger("parent_content_id", table) == parentContentId);
                        q.ExecuteNonQuery();
                    }
                }
            }

        }
    }
开发者ID:kyvkri,项目名称:mgone,代码行数:59,代码来源:Default.aspx.cs

示例7: deleteUnusedClassTableRecords

 HashSet<int> deleteUnusedClassTableRecords(Dictionary<int, int> classIdByLegalContentId)
 {
     HashSet<int> allContentIdInClassTables = new HashSet<int>();
     foreach (var classDef in Engine.Definition.ContentClass.Values) {
         bool includeClassTable = true;
         if (!_includeInner) {
             includeClassTable = classDef.ClassType == ContentClassType.ContentClass;
         }
         if (classDef.Id == 0) includeClassTable = false;
         if (includeClassTable) {
             var illegalContentIds = new List<int>();
             {
                 var q = new SqlQuery(Engine.Dao);
                 var table = new SqlTable(classDef.TableName);
                 q.From(table);
                 var rContentId = q.Select(new SqlFieldInteger("content_id", table));
                 using (var rs = q.ExecuteReader()) {
                     while (rs.Read()) {
                         if (Info.BreakExecution) return allContentIdInClassTables;
                         var contentId = rContentId.Value;
                         if (classIdByLegalContentId.ContainsKey(rContentId.Value)) {
                             // ok, so it is known, check if class of this table inherits the other
                             int legalClassId = classIdByLegalContentId[rContentId.Value];
                             var classDefLegal = Engine.Definition.ContentClass[legalClassId];
                             if (!classDefLegal.AllParentsIncThis.Contains(classDef.Id)) { // this class table does not inherit from the class content it belongs to
                                 illegalContentIds.Add(contentId);
                             } else { // ok, so leave, and store in list of legal content ids to relate to:
                                 if (!allContentIdInClassTables.Contains(contentId)) allContentIdInClassTables.Add(contentId);
                             }
                         } else { // completely unknown
                             illegalContentIds.Add(contentId);
                         }
                     }
                 }
             }
             {
                 foreach (var contentId in illegalContentIds) {
                     if (Info.BreakExecution) return allContentIdInClassTables;
                     addDeleteCount();
                     if (_delete) {
                         var q = new SqlQuery(Engine.Dao);
                         var table = new SqlTable(classDef.TableName);
                         q.Delete(table);
                         q.Where(new SqlFieldInteger("content_id", table) == contentId);
                         q.ExecuteNonQuery();
                     }
                 }
             }
         }
     }
     return allContentIdInClassTables;
 }
开发者ID:kyvkri,项目名称:mgone,代码行数:52,代码来源:Default.aspx.cs


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