Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezgi Yaman committed Oct 17, 2021
1 parent 8f4eb82 commit 297fc51
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 55 deletions.
1 change: 1 addition & 0 deletions Dapper_Example/Dapper_Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="Entities\Abstract\BaseEntity.cs" />
<Compile Include="Entities\Concretes\Categories.cs" />
<Compile Include="Entities\Concretes\Employees.cs" />
<Compile Include="Entities\Concretes\OrderDetails.cs" />
<Compile Include="Entities\Concretes\Products.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
Expand Down
6 changes: 2 additions & 4 deletions Dapper_Example/Entities/Concretes/Employees.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public class Employees : BaseEntity
public int EmployeeID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Title { get; set; }
public string TitleOfCourtesy { get; set; }
public DateTime BirthDate { get; set; }


public string Country { get; set; }
}
}
17 changes: 17 additions & 0 deletions Dapper_Example/Entities/Concretes/OrderDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Dapper_Example.Entities.Abstract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dapper_Example.Entities.Concretes
{
public class OrderDetails : BaseEntity
{
public int OrderID { get; set; }
public decimal UnitPrice { get; set; }
public int Quantity { get; set; }
public decimal Discount { get; set; }
}
}
2 changes: 2 additions & 0 deletions Dapper_Example/Entities/Concretes/Products.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Products : BaseEntity
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ProductID { get; set; }

public int CategoryID { get; set; }
public string ProductName { get; set; }
public decimal UnitPrice { get; set; }
public int UnitsInStock { get; set; }
Expand Down
152 changes: 102 additions & 50 deletions Dapper_Example/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 46 additions & 1 deletion Dapper_Example/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,52 @@ private void btnExample_4_Click(object sender, EventArgs e)

private void btnExample_5_Click(object sender, EventArgs e)
{

using (IDbConnection con = new SqlConnection("Server =DESKTOP-DF88VQJ;Database=Northwind;Integrated Security=True;"))
{
con.Open();
dataGridView1.DataSource = con.Query("Select OrderID, Sum(Quantity) [Satılan Ürün] from [Order Details] group by OrderID").ToList();
con.Close();
}
}

private void btnExample_6_Click(object sender, EventArgs e)
{
using (IDbConnection con = new SqlConnection("Server =DESKTOP-DF88VQJ;Database=Northwind;Integrated Security=True;"))
{
con.Open();
dataGridView1.DataSource = con.Query("Select OrderID,Sum(UnitPrice * Quantity * (1 - Discount)) as [Tutar] from [Order Details] group by OrderID order by 2 desc").ToList();
con.Close();
}
}
private void btnExample_7_Click(object sender, EventArgs e)
{
using (IDbConnection con = new SqlConnection("Server =DESKTOP-DF88VQJ;Database=Northwind;Integrated Security=True;"))
{
con.Open();
dataGridView1.DataSource = con.Query("Select OrderID, Sum(Quantity) as [Adet] from [Order Details] group by OrderID having sum(Quantity)> 100 order by 2 desc").ToList();
con.Close();
}
}
private void btnExample8_Click(object sender, EventArgs e)
{
//Count
using (IDbConnection con = new SqlConnection("Server =DESKTOP-DF88VQJ;Database=Northwind;Integrated Security=True;"))
{
con.Open();
dataGridView1.DataSource = con.Query("select Country, Count(*) as [Çalışan Sayısı] from Employees group by Country").ToList();
con.Close();
}
}
private void btnExample_9_Click(object sender, EventArgs e)
{
//Join
using (IDbConnection con = new SqlConnection("Server =DESKTOP-DF88VQJ;Database=Northwind;Integrated Security=True;"))
{
con.Open();
dataGridView1.DataSource = con.Query("select c.CategoryID,c.CategoryName, p.ProductID,p.ProductName from Categories c join Products p on c.CategoryID = p.CategoryID ").ToList();
con.Close();
}

}
}
}

0 comments on commit 297fc51

Please sign in to comment.