本文整理汇总了C#中IDbConnection.Get方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnection.Get方法的具体用法?C# IDbConnection.Get怎么用?C# IDbConnection.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbConnection
的用法示例。
在下文中一共展示了IDbConnection.Get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Delete
public ActionResult Delete(int id)
{
try
{
_connection = Connect.Open();
var studentLst = _connection.Get<Student>(id);
_connection.Delete(studentLst);
}
catch(DataException)
{
return RedirectToAction("Delete", new {id, saveChangesError = true});
}
return RedirectToAction("Index");
}
示例2: Get
public GroupSaleVehicle Get(int id, IDbConnection connection)
{
return connection.Get<GroupSaleVehicle>(id);
}
示例3: EditPost
public ActionResult EditPost(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
_connection = Connect.Open();
var studentToUpdate = _connection.Get<Student>(id);
if (TryUpdateModel(studentToUpdate, "", new[]
{
"LastName", "FirstMidName", "EnrollmentDate"
}))
{
try
{
_connection.Update(studentToUpdate);
return RedirectToAction("Index");
}
catch (DataException)
{
ModelState.AddModelError("","Unable to save changes. Try again, and if the problem persist please see your system administrator");
}
}
return View(studentToUpdate);
}
示例4: Edit
// GET: Student/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
_connection = Connect.Open();
var studentLst = _connection.Get<Student>(id);
if (studentLst == null)
{
return HttpNotFound("Student not found");
}
return View(studentLst);
}
示例5: Print
private static void Print(IDbConnection connection, Guid id)
{
var inserted = connection.Get<GrandParent>(new { Id = id });
Console.WriteLine("Date: {0}", inserted.Name);
}
示例6: EditPost
public ActionResult EditPost(int? id, string[] selectedCourses)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
_connection = Connect.Open();
var instructorToUpdate = GetInstructor(id);
var courseLst = GetInstructorCourse(id);
courseLst.ForEach(instructorToUpdate.AddCourse);
if (TryUpdateModel(instructorToUpdate, "",
new[] { "LastName", "FirstMidName", "HireDate", "OfficeAssignment" }))
{
try
{
instructorToUpdate.OfficeAssignment.InstructorId = instructorToUpdate.InstructorId;
var checkOffice = _connection.Get<OfficeAssignment>(id);
if (checkOffice != null)
{
//update OfficeAssignment
_connection.Update(instructorToUpdate.OfficeAssignment);
}
else
{
//insert OfficeAssignment
_connection.Insert(instructorToUpdate.OfficeAssignment);
}
UpdateInstructorCourses(selectedCourses, instructorToUpdate);
_connection.Update(instructorToUpdate);
return RedirectToAction("Index");
}
catch (RetryLimitExceededException)
{
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists please see the administrator.");
}
}
PopulateAssignedCourseData(instructorToUpdate);
return View(instructorToUpdate);
}