本文整理汇总了C#中System.Data.SqlClient.SqlConnection.Get方法的典型用法代码示例。如果您正苦于以下问题:C# SqlConnection.Get方法的具体用法?C# SqlConnection.Get怎么用?C# SqlConnection.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlConnection
的用法示例。
在下文中一共展示了SqlConnection.Get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection))
{
sqlConnection.Open();
var entity = sqlConnection.Get<Supplier>(9);
entity.ContactName = "John Smith";
sqlConnection.Update<Supplier>(entity);
var result = sqlConnection.Get<Supplier>(9);
ObjectDumper.Write(result.ContactName);
}
}
示例2: Main
public static void Main()
{
using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection))
{
sqlConnection.Open();
var result = sqlConnection.Get<Supplier>(9);
ObjectDumper.Write(result);
}
}
示例3: UpdatesWithChangeTracking
public static void UpdatesWithChangeTracking()
{
using (var cn = new SqlConnection(CONNECTION_STRING))
{
var contact = cn.Get<IContact>(1);
Console.WriteLine("Update occurred: {0}", cn.Update(contact));
contact.FirstName = "J.";
Console.WriteLine("Update occurred: {0}", cn.Update(contact));
}
Console.ReadKey();
}
示例4: Dapper
private static void Dapper(int eachCount)
{
GC.Collect();//回收资源
System.Threading.Thread.Sleep(2000);//休息2秒
//正试比拼
PerHelper.Execute(eachCount, "Dapper", () =>
{
using (SqlConnection conn = new SqlConnection(PubConst.connectionString))
{
var list = conn.Get<Test>(1000);
}
});
}
示例5: Update
public static void Update()
{
using (var cn = new SqlConnection(CONNECTION_STRING))
{
cn.Open();
var c = cn.Get<Contact>(1);
c.FirstName = "Jonathan";
var updated = cn.Update(c);
Console.WriteLine("Updated {0}", updated);
}
Console.ReadKey();
}
示例6: GetMethods
public static void GetMethods()
{
using (var cn = new SqlConnection(CONNECTION_STRING))
{
var contact = cn.Get<Contact>(1);
var contacts = cn.GetAll<Contact>();
Console.WriteLine(
"Found contact {0} {1} and {2} total contacts",
contact.FirstName,
contact.LastName,
contacts.Count());
}
Console.ReadKey();
}
示例7: TestPersonWithIdIsOne
public void TestPersonWithIdIsOne()
{
IPerson mockPerson = table.GetTable().First(p => p.Id == 1);
using (SqlConnection conn = new SqlConnection(SqlServerUtility.ConnectionString))
{
conn.Open();
var person = conn.Get<Person>("Select Id,Name From PERSON Where Id = @Id", new { Id = 1 });
Assert.IsNotNull(person);
Assert.AreEqual(mockPerson.Id, person.Id);
Assert.AreEqual(mockPerson.Name, person.Name);
}
}
示例8: Main
public static void Main()
{
using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection))
{
sqlConnection.Open();
// using interface to track "Isdirty"
var supplier = sqlConnection.Get<ISupplier>(9);
//supplier.CompanyName = "Manning";
// should return false, becasue there is no change.
ObjectDumper.Write(string.Format("Is Update {0}", sqlConnection.Update(supplier)));
supplier.CompanyName = "Manning";
// should return true
ObjectDumper.Write(string.Format("Is Update {0}", sqlConnection.Update(supplier)));
}
}
示例9: GetAllWithId5
public void GetAllWithId5()
{
IPerson mockPerson = table.GetTable().First(p => p.Id == 5);
using (SqlConnection conn = new SqlConnection(SqlServerUtility.ConnectionString))
{
conn.Open();
var person = conn.Get<Person>("Select * From PERSON Where Id = @Id", new { Id = 5 });
Assert.IsNotNull(person);
Assert.AreEqual(mockPerson.Id, person.Id);
Assert.AreEqual(mockPerson.Name, person.Name);
Assert.AreEqual(mockPerson.DateOfBirth, person.DateOfBirth);
Assert.AreEqual(mockPerson.SSN, person.SSN);
Assert.AreEqual(mockPerson.BankAccount, person.BankAccount);
Assert.AreEqual(mockPerson.NoofCars, person.NoofCars);
Assert.AreEqual(mockPerson.IsPremium, person.IsPremium);
}
}
示例10: CustomerCRUD
/// <summary>
/// Customers the CRUD.
/// </summary>
/// <param name="sqlconn">The sqlconn.</param>
/// <remarks>http://wintersun.cnblogs.com/</remarks>
private static void CustomerCRUD(SqlConnection sqlconn)
{
var customer = new Customers
{
CustomerID = "8273",
CompanyName = "Newcompanyname",
ContactName = "ccc",
Address = "asdcasdws",
ContactTitle = "asdf",
City = "kuna",
Country = "china",
Fax = "23",
Phone = "231",
PostalCode = "234",
Region = "asia"
};
string insertflag = sqlconn.Insert<Customers>(customer);
//update it
var myCustomer = sqlconn.Get<Customers>(customer.CustomerID);
myCustomer.ContactName = "updated name";
sqlconn.Update<Customers>(myCustomer);
//delete
sqlconn.Delete<Customers>(customer);
}
开发者ID:megadotnet,项目名称:DotNetDataAccessPerformanceProfiler,代码行数:33,代码来源:DapperExtentsionsPerformanceTest.cs
示例11: NullName
public void NullName()
{
using (SqlConnection conn = new SqlConnection(SqlServerUtility.ConnectionString))
{
conn.Open();
var person = conn.Get<Person>("Select NULL As Name");
Assert.IsNotNull(person);
Assert.AreEqual(null, person.Name);
}
}