• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# SQL.SQLHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Utilities.SQL.SQLHelper的典型用法代码示例。如果您正苦于以下问题:C# SQLHelper类的具体用法?C# SQLHelper怎么用?C# SQLHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SQLHelper类属于Utilities.SQL命名空间,在下文中一共展示了SQLHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: All

 public void All()
 {
     Utilities.SQL.SQLHelper.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
     Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_")
             .Map(x => x.ID, "ID_")
             .Map(x => x.StringValue, "StringValue_")
             .Map(x => x.FloatValue, "FloatValue_")
             .Map(x => x.BoolValue, "BoolValue_")
             .Map(x => x.LongValue, "LongValue_");
     ObjectClass1 TempObject = null;
     Utilities.Random.Random Rand = new Utilities.Random.Random();
     using (Utilities.SQL.SQLHelper ORM = new Utilities.SQL.SQLHelper())
     {
         for (int x = 0; x < 100; ++x)
         {
             TempObject = new ObjectClass1();
             TempObject.StringValue = Rand.Next<string>(new RegexStringGenerator(10));
             TempObject.BoolValue = Rand.Next<bool>();
             TempObject.FloatValue = (float)Rand.NextDouble();
             TempObject.LongValue =Rand.Next();
             ORM.Save<ObjectClass1, int>(TempObject);
         }
         TempObject = null;
         IEnumerable<ObjectClass1> Objects = ORM.All<ObjectClass1>();
         Assert.Equal(100, Objects.Count());
     }
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:27,代码来源:MicroORM.cs


示例2: Creation

 public void Creation()
 {
     Utilities.SQL.ParameterTypes.OrParameter TestObject = new Utilities.SQL.ParameterTypes.OrParameter(new EqualParameter<int>(1, "Left"), new EqualParameter<int>(2, "Right"));
     Assert.Equal("([email protected] OR [email protected])", TestObject.ToString());
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Assert.DoesNotThrow<Exception>(() => TestObject.AddParameter(Helper));
     }
 }
开发者ID:gwilkinson,项目名称:Craig-s-Utility-Library,代码行数:9,代码来源:OrParameter.cs


示例3: BulkCopy

 public void BulkCopy()
 {
     Guid TempGuid=Guid.NewGuid();
     List<BulkCopyObject> Objects = new List<BulkCopyObject>();
     for (int x = 0; x < 100; ++x)
     {
         BulkCopyObject TempObject = new BulkCopyObject();
         TempObject.BigIntValue = 12345;
         TempObject.BitValue = true;
         TempObject.DateTimeValue = new DateTime(1999, 12, 31);
         TempObject.DecimalValue = 1234.5678m;
         TempObject.FloatValue = 12345.6534f;
         TempObject.GUIDValue = TempGuid;
         TempObject.ID = x+1;
         TempObject.StringValue1 = "Test String";
         TempObject.StringValue2 = "Test String";
         Objects.Add(TempObject);
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.ExecuteBulkCopy(Objects.ToDataTable(),"TestTable");
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.ExecuteReader();
         bool Inserted=false;
         while (Helper.Read())
         {
             Inserted=true;
             Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", ""));
             Assert.Equal("Test String", Helper.GetParameter<string>("StringValue2", ""));
             Assert.Equal(12345, Helper.GetParameter<long>("BigIntValue", 0));
             Assert.Equal(true, Helper.GetParameter<bool>("BitValue", false));
             Assert.Equal(1234.5678m, Helper.GetParameter<decimal>("DecimalValue", 0));
             Assert.Equal(12345.6534f, Helper.GetParameter<float>("FloatValue", 0));
             Assert.Equal(TempGuid, Helper.GetParameter<Guid>("GUIDValue", Guid.Empty));
             Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter<DateTime>("DateTimeValue", DateTime.Now));
         }
         if(!Inserted)
         {
             Assert.Fail("Nothing was inserted");
         }
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT COUNT(*) as [ItemCount] FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.ExecuteReader();
         if (Helper.Read())
         {
             Assert.Equal(100, Helper.GetParameter<int>("ItemCount", 0));
         }
         else
         {
             Assert.Fail("Nothing was inserted");
         }
     }
 }
开发者ID:jpsullivan,项目名称:Craig-s-Utility-Library,代码行数:56,代码来源:SQLHelper.cs


示例4: Dispose

 public void Dispose()
 {
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.Batch().AddCommand("ALTER DATABASE TestDatabase SET OFFLINE WITH ROLLBACK IMMEDIATE", CommandType.Text)
             .AddCommand("ALTER DATABASE TestDatabase SET ONLINE", CommandType.Text)
             .AddCommand("DROP DATABASE TestDatabase", CommandType.Text);
         Helper.ExecuteNonQuery();
     }
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:10,代码来源:SQLServer.cs


示例5: Mapping

        public Mapping()
        {
            using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Database TestDatabase", "Data Source=localhost;Integrated Security=SSPI;Pooling=false", CommandType.Text))
            {
                Helper.ExecuteNonQuery();

            }
            using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Table TestTable(ID_ INT PRIMARY KEY IDENTITY,StringValue_ NVARCHAR(100),LongValue_ BIGINT,BoolValue_ BIT,FloatValue_ FLOAT,StringMaxValue_ NVARCHAR(MAX))", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
            {
                Helper.ExecuteNonQuery();
            }
        }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:12,代码来源:Mapping.cs


示例6: Creation

 public void Creation()
 {
     Parameter<int> TestObject = new Parameter<int>(12, "ID");
     Assert.Equal("ID", TestObject.ID);
     Assert.Equal(12, TestObject.Value);
     Assert.Equal("@", TestObject.ParameterStarter);
     Assert.Equal("[email protected]", TestObject.ToString());
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Assert.DoesNotThrow<Exception>(() => TestObject.AddParameter(Helper));
     }
 }
开发者ID:JKLFA,项目名称:Craig-s-Utility-Library,代码行数:12,代码来源:Parameter.cs


示例7: SQLHelper

        public SQLHelper()
        {
            using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Database TestDatabase", "Data Source=localhost;Integrated Security=SSPI;Pooling=false", CommandType.Text))
            {
                Helper.ExecuteNonQuery();

            }
            using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Table TestTable(ID INT PRIMARY KEY IDENTITY,StringValue1 NVARCHAR(100),StringValue2 NVARCHAR(MAX),BigIntValue BIGINT,BitValue BIT,DecimalValue DECIMAL(12,6),FloatValue FLOAT,DateTimeValue DATETIME,GUIDValue UNIQUEIDENTIFIER)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
            {
                Helper.ExecuteNonQuery();
            }
        }
开发者ID:jpsullivan,项目名称:Craig-s-Utility-Library,代码行数:12,代码来源:SQLHelper.cs


示例8: Creation

 public void Creation()
 {
     Utilities.SQL.ParameterTypes.StringEqualParameter TestObject = new Utilities.SQL.ParameterTypes.StringEqualParameter("ASDF", "ID", 100);
     Assert.Equal("ID", TestObject.ID);
     Assert.Equal("ASDF", TestObject.Value);
     Assert.Equal("@", TestObject.ParameterStarter);
     Assert.Equal("[email protected]", TestObject.ToString());
     Assert.Equal(100, TestObject.Length);
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Assert.DoesNotThrow(() => Helper.AddParameter(TestObject));
     }
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:13,代码来源:StringEqualParamter.cs


示例9: Creation

 public void Creation()
 {
     BetweenParameter<int> TestObject = new BetweenParameter<int>(10, 12, "ID");
     Assert.Equal("ID", TestObject.ID);
     Assert.Equal(10, TestObject.Min);
     Assert.Equal(12, TestObject.Max);
     Assert.Equal("@", TestObject.ParameterStarter);
     Assert.Equal("ID BETWEEN @IDMin AND @IDMax", TestObject.ToString());
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Assert.DoesNotThrow(() => Helper.AddParameter(TestObject));
     }
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:13,代码来源:BetweenParameter.cs


示例10: CreateDatabase

 public void CreateDatabase()
 {
     Database Database = new Database("TestDatabase");
     Table TestTable = Database.AddTable("TestTable");
     TestTable.AddColumn<string>("ID_", DbType.Int32);
     TestTable.AddColumn<string>("Value1", DbType.String, 100);
     TestTable.AddColumn<string>("Value2", DbType.Double);
     Utilities.SQL.SQLServer.SQLServer.CreateDatabase(Database, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(ID_,Value1,Value2) VALUES (@ID_,@Value1,@Value2)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.AddParameter<int>("@ID_", 1);
         Helper.AddParameter<string>("@Value1", "Test String");
         Helper.AddParameter<float>("@Value2", 3.0f);
         Assert.Equal(1, Helper.ExecuteNonQuery());
     }
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:16,代码来源:SQLServer.cs


示例11: All

 public void All()
 {
     using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_");
         TestObject.Map(x => x.ID, "ID_")
             .Map(x => x.StringValue, "StringValue_")
             .Map(x => x.FloatValue, "FloatValue_")
             .Map(x => x.BoolValue, "BoolValue_")
             .Map(x => x.LongValue, "LongValue_")
             .Map(x => x.StringMaxValue, "StringMaxValue_");
         Utilities.Random.Random Rand = new Utilities.Random.Random(12345);
         ObjectClass1 TempObject = new ObjectClass1();
         TempObject.StringValue = "Test String";
         TempObject.BoolValue = true;
         TempObject.FloatValue = 1234.5f;
         TempObject.LongValue = 12345;
         TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000));
         Helper2.Save<ObjectClass1, int>(TempObject);
         IEnumerable<ObjectClass1> Objects = Helper2.All<ObjectClass1>();
         Assert.Equal(1, Objects.Count());
         foreach (ObjectClass1 Item in Objects)
         {
             Assert.Equal("Test String", Item.StringValue);
             Assert.Equal(1234.5f, Item.FloatValue);
             Assert.Equal(true, Item.BoolValue);
             Assert.Equal(12345, Item.LongValue);
             Assert.Equal(1, Item.ID);
             Assert.Equal(TempObject.StringMaxValue, Item.StringMaxValue);
         }
         List<ObjectClass1> Objects2 = new List<ObjectClass1>();
         Rand = new Utilities.Random.Random();
         for (int x = 0; x < 10; ++x)
         {
             TempObject = new ObjectClass1();
             TempObject.StringValue = Rand.Next<string>(new RegexStringGenerator(10));
             TempObject.BoolValue = Rand.Next<bool>();
             TempObject.FloatValue = (float)Rand.NextDouble();
             TempObject.LongValue = Rand.Next(0, 100);
             TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000));
             Objects2.Add(TempObject);
         }
         Helper2.Save<ObjectClass1, int>(Objects2);
         Objects = Helper2.All<ObjectClass1>();
         Assert.Equal(11, Objects.Count());
     }
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:47,代码来源:Mapping.cs


示例12: ClearParameters

 public void ClearParameters()
 {
     Guid TempGuid = Guid.NewGuid();
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.AddParameter<string>("@StringValue1", "Test");
         Helper.AddParameter<string>("@StringValue2", "Test");
         Helper.AddParameter<long>("@BigIntValue", 123);
         Helper.AddParameter<bool>("@BitValue", false);
         Helper.AddParameter<decimal>("@DecimalValue", 1234);
         Helper.AddParameter<float>("@FloatValue", 12345);
         Helper.AddParameter<Guid>("@GUIDValue", Guid.NewGuid());
         Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 1, 1));
         Helper.ClearParameters();
         Helper.AddParameter<string>("@StringValue1", "Test String");
         Helper.AddParameter<string>("@StringValue2", "Test String");
         Helper.AddParameter<long>("@BigIntValue", 12345);
         Helper.AddParameter<bool>("@BitValue", true);
         Helper.AddParameter<decimal>("@DecimalValue", 1234.5678m);
         Helper.AddParameter<float>("@FloatValue", 12345.6534f);
         Helper.AddParameter<Guid>("@GUIDValue", TempGuid);
         Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31));
         Helper.ExecuteNonQuery();
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.ExecuteReader();
         if (Helper.Read())
         {
             Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", ""));
             Assert.Equal("Test String", Helper.GetParameter<string>("StringValue2", ""));
             Assert.Equal(12345, Helper.GetParameter<long>("BigIntValue", 0));
             Assert.Equal(true, Helper.GetParameter<bool>("BitValue", false));
             Assert.Equal(1234.5678m, Helper.GetParameter<decimal>("DecimalValue", 0));
             Assert.Equal(12345.6534f, Helper.GetParameter<float>("FloatValue", 0));
             Assert.Equal(TempGuid, Helper.GetParameter<Guid>("GUIDValue", Guid.Empty));
             Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter<DateTime>("DateTimeValue", DateTime.Now));
         }
         else
         {
             Assert.Fail("Nothing was inserted");
         }
     }
 }
开发者ID:JKLFA,项目名称:Craig-s-Utility-Library,代码行数:44,代码来源:SQLHelper.cs


示例13: Update

 public void Update()
 {
     using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_");
         TestObject.Map(x => x.ID, "ID_")
             .Map(x => x.StringValue, "StringValue_")
             .Map(x => x.FloatValue, "FloatValue_")
             .Map(x => x.BoolValue, "BoolValue_")
             .Map(x => x.LongValue, "LongValue_")
             .Map(x => x.StringMaxValue, "StringMaxValue_");
         Utilities.Random.Random Rand = new Utilities.Random.Random(12346);
         ObjectClass1 TempObject = new ObjectClass1();
         TempObject.StringValue = "Test";
         TempObject.BoolValue = false;
         TempObject.FloatValue = 1.5f;
         TempObject.LongValue = 12;
         TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000));
         TempObject.ID = Helper2.Insert<ObjectClass1, int>(TempObject);
         Rand = new Utilities.Random.Random(12345);
         TempObject.StringValue = "Test String";
         TempObject.BoolValue = true;
         TempObject.FloatValue = 1234.5f;
         TempObject.LongValue = 12345;
         TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000));
         Helper2.Update(TempObject);
         using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
         {
             Helper.ExecuteReader();
             if (Helper.Read())
             {
                 Assert.Equal("Test String", Helper.GetParameter<string>("StringValue_", ""));
                 Assert.Equal(1234.5f, Helper.GetParameter<float>("FloatValue_", 0));
                 Assert.Equal(true, Helper.GetParameter<bool>("BoolValue_", false));
                 Assert.Equal(12345, Helper.GetParameter<long>("LongValue_", 0));
                 Assert.Equal(TempObject.ID, Helper.GetParameter<int>("ID_", 0));
                 Assert.Equal(TempObject.StringMaxValue, Helper.GetParameter<string>("StringMaxValue_", ""));
             }
             else
             {
                 Assert.False(true,"Nothing was inserted");
             }
         }
     }
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:45,代码来源:Mapping.cs


示例14: Paged2

        public void Paged2()
        {
            using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
            {
                Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_");
                TestObject.Map(x => x.ID, "ID_")
                    .Map(x => x.StringValue, "StringValue_")
                    .Map(x => x.FloatValue, "FloatValue_")
                    .Map(x => x.BoolValue, "BoolValue_")
                    .Map(x => x.LongValue, "LongValue_")
                    .Map(x => x.StringMaxValue, "StringMaxValue_");
                List<ObjectClass1> Objects2 = new List<ObjectClass1>();
                Utilities.Random.Random Rand = new Utilities.Random.Random();
                for (int x = 0; x < 115; ++x)
                {
                    ObjectClass1 TempObject = new ObjectClass1();
                    TempObject.StringValue = Rand.Next<string>(new RegexStringGenerator(10));
                    TempObject.BoolValue = Rand.Next<bool>();
                    TempObject.FloatValue = (float)Rand.NextDouble();
                    TempObject.LongValue = Rand.Next(0, 100);
                    TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000));
                    Objects2.Add(TempObject);
                }
                Helper2.Save<ObjectClass1, int>(Objects2);
                IEnumerable<ObjectClass1> Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable");
                Assert.Equal(25, Objects.Count());
                Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable", CurrentPage: 1);
                Assert.Equal(25, Objects.Count());
                Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable", CurrentPage: 2);
                Assert.Equal(25, Objects.Count());
                Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable", CurrentPage: 3);
                Assert.Equal(25, Objects.Count());
                Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable", CurrentPage: 4);
                Assert.Equal(15, Objects.Count());
                Assert.Equal(5, Helper2.PageCount<ObjectClass1>("SELECT * FROM TestTable"));

                Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable WHERE ID_>@ID", "", 25, 0, null, null, false, new EqualParameter<int>(50, "ID"));
                Assert.Equal(25, Objects.Count());
                Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable WHERE ID_>@ID", "", 25, 1, null, null, false, new EqualParameter<int>(50, "ID"));
                Assert.Equal(25, Objects.Count());
                Objects = Helper2.PagedCommand<ObjectClass1>("SELECT * FROM TestTable WHERE ID_>@ID", "", 25, 2, null, null, false, new EqualParameter<int>(50, "ID"));
                Assert.Equal(15, Objects.Count());
                Assert.Equal(3, Helper2.PageCount<ObjectClass1>("SELECT * FROM TestTable WHERE ID_>@ID", 25, false, new EqualParameter<int>(50, "ID")));
            }
        }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:45,代码来源:Mapping.cs


示例15: Scalar

 public void Scalar()
 {
     using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_");
         TestObject.Map(x => x.ID, "ID_")
             .Map(x => x.StringValue, "StringValue_")
             .Map(x => x.FloatValue, "FloatValue_")
             .Map(x => x.BoolValue, "BoolValue_")
             .Map(x => x.LongValue, "LongValue_")
             .Map(x => x.StringMaxValue, "StringMaxValue_");
         Utilities.Random.Random Rand = new Utilities.Random.Random(12345);
         for (int x = 0; x < 100; ++x)
         {
             ObjectClass1 TempObject = new ObjectClass1();
             TempObject.StringValue = "Test String";
             TempObject.BoolValue = true;
             TempObject.FloatValue = 1234.5f;
             TempObject.LongValue = 12345;
             TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000));
             string StringMaxValue = TempObject.StringMaxValue;
             Helper2.Save<ObjectClass1, int>(TempObject);
         }
         int ASD = Helper2.Scalar<ObjectClass1, int>("SELECT COUNT(*) FROM TestTable", CommandType.Text);
         Assert.Equal(100, ASD);
         ASD = Helper2.Scalar<ObjectClass1, int>("COUNT(*)");
         Assert.Equal(100, ASD);
     }
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:29,代码来源:Mapping.cs


示例16: Creation

 public void Creation()
 {
     Assert.DoesNotThrow(() =>
     {
         Mapping<ObjectClass1> TestObject = new Mapping<ObjectClass1>("TestTable", "ID_");
         using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
         {
             Mapping<ObjectClass1> TestObject2 = new Mapping<ObjectClass1>(TestObject);
         }
         TestObject = new Mapping<ObjectClass1>("TestTable", "ID_");
     });
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:12,代码来源:Mapping.cs


示例17: Delete

        public void Delete()
        {
            using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("","Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false",CommandType.Text))
            {
                Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_");
                TestObject.Map(x => x.ID, "ID_")
                    .Map(x => x.StringValue, "StringValue_")
                    .Map(x => x.FloatValue, "FloatValue_")
                    .Map(x => x.BoolValue, "BoolValue_")
                    .Map(x => x.LongValue, "LongValue_")
                    .Map(x => x.StringMaxValue, "StringMaxValue_");
                Utilities.Random.Random Rand = new Utilities.Random.Random();
                ObjectClass1 TempObject = new ObjectClass1();
                TempObject.StringValue = "Test";
                TempObject.BoolValue = false;
                TempObject.FloatValue = 1.5f;
                TempObject.LongValue = 12;
                TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000));
                Helper2.Save<ObjectClass1, int>(TempObject);
                Assert.Equal(1, Helper2.Delete<ObjectClass1>(TempObject));

                using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT COUNT(*) AS ItemCount FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
                {
                    Helper.ExecuteReader();
                    if (Helper.Read())
                    {
                        Assert.Equal(0, Helper.GetParameter<int>("ItemCount", -1));
                    }
                    else
                    {
                        Assert.False(true,"Nothing was inserted");
                    }
                }
            }
        }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:35,代码来源:Mapping.cs


示例18: Delete

 public void Delete()
 {
     Guid TempGuid = Guid.NewGuid();
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.AddParameter<string>("@StringValue1", "Test String");
         Helper.AddParameter<string>("@StringValue2", "Test String");
         Helper.AddParameter<long>("@BigIntValue", 12345);
         Helper.AddParameter<bool>("@BitValue", true);
         Helper.AddParameter<decimal>("@DecimalValue", 1234.5678m);
         Helper.AddParameter<float>("@FloatValue", 12345.6534f);
         Helper.AddParameter<Guid>("@GUIDValue", TempGuid);
         Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31));
         Helper.ExecuteNonQuery();
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("delete from TestTable where @ID=ID", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.AddParameter<int>("@ID", 1);
         Helper.ExecuteNonQuery();
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.ExecuteReader();
         if (Helper.Read())
         {
             Assert.Fail("Nothing was deleted");
         }
     }
 }
开发者ID:jpsullivan,项目名称:Craig-s-Utility-Library,代码行数:29,代码来源:SQLHelper.cs


示例19: Any

 public void Any()
 {
     using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_");
         TestObject.Map(x => x.ID, "ID_")
             .Map(x => x.StringValue, "StringValue_")
             .Map(x => x.FloatValue, "FloatValue_")
             .Map(x => x.BoolValue, "BoolValue_")
             .Map(x => x.LongValue, "LongValue_")
             .Map(x => x.StringMaxValue, "StringMaxValue_");
         Utilities.Random.Random Rand = new Utilities.Random.Random(12345);
         ObjectClass1 TempObject = new ObjectClass1();
         TempObject.StringValue = "Test String";
         TempObject.BoolValue = true;
         TempObject.FloatValue = 1234.5f;
         TempObject.LongValue = 12345;
         TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000));
         string StringMaxValue = TempObject.StringMaxValue;
         Helper2.Save<ObjectClass1, int>(TempObject);
         TempObject = Helper2.Any<ObjectClass1>();
         Assert.Equal("Test String", TempObject.StringValue);
         Assert.Equal(1234.5f, TempObject.FloatValue);
         Assert.Equal(true, TempObject.BoolValue);
         Assert.Equal(12345, TempObject.LongValue);
         Assert.Equal(1, TempObject.ID);
         Assert.Equal(StringMaxValue, TempObject.StringMaxValue);
     }
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:29,代码来源:Mapping.cs


示例20: Save

 public void Save()
 {
     Utilities.SQL.SQLHelper.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
     Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable","ID_")
             .Map(x => x.ID, "ID_")
             .Map(x => x.StringValue, "StringValue_")
             .Map(x => x.FloatValue, "FloatValue_")
             .Map(x => x.BoolValue, "BoolValue_")
             .Map(x => x.LongValue, "LongValue_");
     ObjectClass1 TempObject = new ObjectClass1();
     using (Utilities.SQL.SQLHelper ORM = new Utilities.SQL.SQLHelper())
     {
         TempObject.StringValue = "Test";
         TempObject.BoolValue = false;
         TempObject.FloatValue = 1.5f;
         TempObject.LongValue = 12;
         ORM.Save<ObjectClass1, int>(TempObject);
         TempObject.StringValue = "Test String";
         TempObject.BoolValue = true;
         TempObject.FloatValue = 1234.5f;
         TempObject.LongValue = 12345;
         ORM.Save<ObjectClass1,int>(TempObject);
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.ExecuteReader();
         if (Helper.Read())
         {
             Assert.Equal("Test String", Helper.GetParameter<string>("StringValue_", ""));
             Assert.Equal(1234.5f, Helper.GetParameter<float>("FloatValue_", 0));
             Assert.Equal(true, Helper.GetParameter<bool>("BoolValue_", false));
             Assert.Equal(12345, Helper.GetParameter<long>("LongValue_", 0));
             Assert.Equal(TempObject.ID, Helper.GetParameter<int>("ID_", 0));
         }
         else
         {
             Assert.False(true,"Nothing was inserted");
         }
     }
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:40,代码来源:MicroORM.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# RDF.Graph类代码示例发布时间:2022-05-26
下一篇:
C# Utilities.DBConnect类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap