本文整理汇总了C#中Utilities.SQL.SQLHelper.Save方法的典型用法代码示例。如果您正苦于以下问题:C# SQLHelper.Save方法的具体用法?C# SQLHelper.Save怎么用?C# SQLHelper.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utilities.SQL.SQLHelper
的用法示例。
在下文中一共展示了SQLHelper.Save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
}
示例2: 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);
}
}
示例3: Save
public void Save()
{
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));
Helper2.Save<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.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));
Assert.Equal(TempObject.StringMaxValue, Helper.GetParameter<string>("StringMaxValue_", ""));
}
else
{
Assert.False(true,"Nothing was inserted");
}
}
}
}
示例4: 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")));
}
}
示例5: 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);
}
}
示例6: Any
public void Any()
{
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 String";
TempObject.BoolValue = true;
TempObject.FloatValue = 1234.5f;
TempObject.LongValue = 12345;
ORM.Save<ObjectClass1,int>(TempObject);
TempObject = null;
TempObject = ORM.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);
}
}
示例7: 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());
}
}