diff --git a/Dapper_Example/App.config b/Dapper_Example/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/Dapper_Example/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dapper_Example/Dapper_Example.csproj b/Dapper_Example/Dapper_Example.csproj new file mode 100644 index 0000000..14d482e --- /dev/null +++ b/Dapper_Example/Dapper_Example.csproj @@ -0,0 +1,92 @@ + + + + + Debug + AnyCPU + {8F1AE2EF-5FF7-495E-9CC2-B5F2755795B3} + WinExe + Dapper_Example + Dapper_Example + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Dapper.2.0.90\lib\net461\Dapper.dll + + + + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/Dapper_Example/Entities/Abstract/BaseEntity.cs b/Dapper_Example/Entities/Abstract/BaseEntity.cs new file mode 100644 index 0000000..b28bf22 --- /dev/null +++ b/Dapper_Example/Entities/Abstract/BaseEntity.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Dapper_Example.Entities.Abstract +{ + public enum Status { Active = 1, Modified = 2, Deleted = 3 } + public abstract class BaseEntity + { + private DateTime _createDate = DateTime.Now; + public DateTime CreatDate { get => _createDate; set => _createDate = value; } + public DateTime? UpdateDate { get; set; } + public DateTime? DeleteDate { get; set; } + + private Status _status = Status.Active; + public Status Status { get => _status; set => _status = value; } + + } +} diff --git a/Dapper_Example/Entities/Concretes/Employees.cs b/Dapper_Example/Entities/Concretes/Employees.cs new file mode 100644 index 0000000..e5aac31 --- /dev/null +++ b/Dapper_Example/Entities/Concretes/Employees.cs @@ -0,0 +1,26 @@ +using Dapper_Example.Entities.Abstract; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + + +namespace Dapper_Example.Entities.Concretes +{ + public class Employees : BaseEntity + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + 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; } + + } +} diff --git a/Dapper_Example/Entities/Concretes/Products.cs b/Dapper_Example/Entities/Concretes/Products.cs new file mode 100644 index 0000000..7a9cbc4 --- /dev/null +++ b/Dapper_Example/Entities/Concretes/Products.cs @@ -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 Products : BaseEntity + { + public int ProductID { get; set; } + public string ProductName { get; set; } + public decimal UnitPrice { get; set; } + public int UnitsInStock { get; set; } + } +} diff --git a/Dapper_Example/Form1.Designer.cs b/Dapper_Example/Form1.Designer.cs new file mode 100644 index 0000000..4fac406 --- /dev/null +++ b/Dapper_Example/Form1.Designer.cs @@ -0,0 +1,174 @@ + +namespace Dapper_Example +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.button1 = new System.Windows.Forms.Button(); + this.btnExample_1 = new System.Windows.Forms.Button(); + this.btnExample_2 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + this.button6 = new System.Windows.Forms.Button(); + this.button7 = new System.Windows.Forms.Button(); + this.button8 = new System.Windows.Forms.Button(); + this.button9 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(12, 358); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 51; + this.dataGridView1.RowTemplate.Height = 24; + this.dataGridView1.Size = new System.Drawing.Size(754, 194); + this.dataGridView1.TabIndex = 0; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(992, 443); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(159, 68); + this.button1.TabIndex = 1; + this.button1.Text = "button1"; + this.button1.UseVisualStyleBackColor = true; + // + // btnExample_1 + // + this.btnExample_1.Location = new System.Drawing.Point(12, 12); + this.btnExample_1.Name = "btnExample_1"; + this.btnExample_1.Size = new System.Drawing.Size(159, 68); + this.btnExample_1.TabIndex = 1; + this.btnExample_1.Text = "Example1"; + this.btnExample_1.UseVisualStyleBackColor = true; + this.btnExample_1.Click += new System.EventHandler(this.btnExample_1_Click); + // + // btnExample_2 + // + this.btnExample_2.Location = new System.Drawing.Point(12, 99); + this.btnExample_2.Name = "btnExample_2"; + this.btnExample_2.Size = new System.Drawing.Size(159, 68); + this.btnExample_2.TabIndex = 1; + this.btnExample_2.Text = "Example2"; + this.btnExample_2.UseVisualStyleBackColor = true; + this.btnExample_2.Click += new System.EventHandler(this.btnExample_2_Click); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(12, 186); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(159, 68); + this.button4.TabIndex = 1; + this.button4.Text = "button1"; + this.button4.UseVisualStyleBackColor = true; + // + // button5 + // + this.button5.Location = new System.Drawing.Point(12, 272); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(159, 68); + this.button5.TabIndex = 1; + this.button5.Text = "button1"; + this.button5.UseVisualStyleBackColor = true; + // + // button6 + // + this.button6.Location = new System.Drawing.Point(200, 12); + this.button6.Name = "button6"; + this.button6.Size = new System.Drawing.Size(159, 68); + this.button6.TabIndex = 1; + this.button6.Text = "button1"; + this.button6.UseVisualStyleBackColor = true; + // + // button7 + // + this.button7.Location = new System.Drawing.Point(200, 99); + this.button7.Name = "button7"; + this.button7.Size = new System.Drawing.Size(159, 68); + this.button7.TabIndex = 1; + this.button7.Text = "button1"; + this.button7.UseVisualStyleBackColor = true; + // + // button8 + // + this.button8.Location = new System.Drawing.Point(200, 186); + this.button8.Name = "button8"; + this.button8.Size = new System.Drawing.Size(159, 68); + this.button8.TabIndex = 1; + this.button8.Text = "button1"; + this.button8.UseVisualStyleBackColor = true; + // + // button9 + // + this.button9.Location = new System.Drawing.Point(200, 272); + this.button9.Name = "button9"; + this.button9.Size = new System.Drawing.Size(159, 68); + this.button9.TabIndex = 1; + this.button9.Text = "button1"; + this.button9.UseVisualStyleBackColor = true; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1227, 574); + this.Controls.Add(this.btnExample_1); + this.Controls.Add(this.btnExample_2); + this.Controls.Add(this.button4); + this.Controls.Add(this.button5); + this.Controls.Add(this.button6); + this.Controls.Add(this.button7); + this.Controls.Add(this.button8); + this.Controls.Add(this.button9); + this.Controls.Add(this.button1); + this.Controls.Add(this.dataGridView1); + this.Name = "Form1"; + this.Text = "Form1"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button btnExample_1; + private System.Windows.Forms.Button btnExample_2; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.Button button6; + private System.Windows.Forms.Button button7; + private System.Windows.Forms.Button button8; + private System.Windows.Forms.Button button9; + } +} + diff --git a/Dapper_Example/Form1.cs b/Dapper_Example/Form1.cs new file mode 100644 index 0000000..9c1ee12 --- /dev/null +++ b/Dapper_Example/Form1.cs @@ -0,0 +1,40 @@ +using Dapper; +using Dapper_Example.Entities.Concretes; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Data.SqlClient; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Dapper_Example +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + public void EmployeesChoose() + { + using (IDbConnection connection = new SqlConnection("Server =DESKTOP-DF88VQJ;Database=Northwind;Integrated Security=True;")) + { + connection.Open(); + List employees = connection.Query("Select * from Employees Where EmployeeID > 5 ").ToList(); + dataGridView1.DataSource = employees; + connection.Close(); + } + } + + private void btnExample_1_Click(object sender, EventArgs e) + { + EmployeesChoose(); + } + + } +} diff --git a/Dapper_Example/Form1.resx b/Dapper_Example/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Dapper_Example/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Dapper_Example/Program.cs b/Dapper_Example/Program.cs new file mode 100644 index 0000000..7bb3d92 --- /dev/null +++ b/Dapper_Example/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Dapper_Example +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/Dapper_Example/Properties/AssemblyInfo.cs b/Dapper_Example/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..edc9c7e --- /dev/null +++ b/Dapper_Example/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Dapper_Example")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Dapper_Example")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8f1ae2ef-5ff7-495e-9cc2-b5f2755795b3")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Dapper_Example/Properties/Resources.Designer.cs b/Dapper_Example/Properties/Resources.Designer.cs new file mode 100644 index 0000000..5e153d4 --- /dev/null +++ b/Dapper_Example/Properties/Resources.Designer.cs @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +namespace Dapper_Example.Properties +{ + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Dapper_Example.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Dapper_Example/Properties/Resources.resx b/Dapper_Example/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Dapper_Example/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Dapper_Example/Properties/Settings.Designer.cs b/Dapper_Example/Properties/Settings.Designer.cs new file mode 100644 index 0000000..090e89f --- /dev/null +++ b/Dapper_Example/Properties/Settings.Designer.cs @@ -0,0 +1,29 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +namespace Dapper_Example.Properties +{ + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Dapper_Example/Properties/Settings.settings b/Dapper_Example/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Dapper_Example/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Dapper_Example/packages.config b/Dapper_Example/packages.config new file mode 100644 index 0000000..236d45d --- /dev/null +++ b/Dapper_Example/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/DataAccess.sln b/DataAccess.sln index d396b83..f291725 100644 --- a/DataAccess.sln +++ b/DataAccess.sln @@ -5,10 +5,12 @@ VisualStudioVersion = 16.0.31702.278 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbFirst_LINO_Methods", "DbFirst_LINO_Methods\DbFirst_LINO_Methods.csproj", "{D17A803F-6168-4CD6-9220-044A99EAC15C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINQ_TO_SQL_EXAMPLE", "LINQ_TO_SQL_EXAMPLE\LINQ_TO_SQL_EXAMPLE.csproj", "{48B7AF67-A2E4-43AF-838B-8885C40D2A08}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINQ_TO_SQL_Example", "LINQ_TO_SQL_EXAMPLE\LINQ_TO_SQL_Example.csproj", "{48B7AF67-A2E4-43AF-838B-8885C40D2A08}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ETicaret_Db_CodeFirst", "ETicaret_Db_CodeFirst\ETicaret_Db_CodeFirst.csproj", "{9F2FC493-F180-4826-9301-681B15101860}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapper_Example", "Dapper_Example\Dapper_Example.csproj", "{8F1AE2EF-5FF7-495E-9CC2-B5F2755795B3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {9F2FC493-F180-4826-9301-681B15101860}.Debug|Any CPU.Build.0 = Debug|Any CPU {9F2FC493-F180-4826-9301-681B15101860}.Release|Any CPU.ActiveCfg = Release|Any CPU {9F2FC493-F180-4826-9301-681B15101860}.Release|Any CPU.Build.0 = Release|Any CPU + {8F1AE2EF-5FF7-495E-9CC2-B5F2755795B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8F1AE2EF-5FF7-495E-9CC2-B5F2755795B3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8F1AE2EF-5FF7-495E-9CC2-B5F2755795B3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8F1AE2EF-5FF7-495E-9CC2-B5F2755795B3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LINQ_TO_SQL_EXAMPLE/Form1.Designer.cs b/LINQ_TO_SQL_EXAMPLE/Form1.Designer.cs index bdb6a54..b4d5f1f 100644 --- a/LINQ_TO_SQL_EXAMPLE/Form1.Designer.cs +++ b/LINQ_TO_SQL_EXAMPLE/Form1.Designer.cs @@ -39,18 +39,18 @@ private void InitializeComponent() // dataGridView1 // this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView1.Location = new System.Drawing.Point(42, 39); + this.dataGridView1.Location = new System.Drawing.Point(73, 39); this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.RowHeadersWidth = 51; this.dataGridView1.RowTemplate.Height = 24; - this.dataGridView1.Size = new System.Drawing.Size(576, 150); + this.dataGridView1.Size = new System.Drawing.Size(545, 150); this.dataGridView1.TabIndex = 0; // // btnExample1 // - this.btnExample1.Location = new System.Drawing.Point(42, 210); + this.btnExample1.Location = new System.Drawing.Point(73, 211); this.btnExample1.Name = "btnExample1"; - this.btnExample1.Size = new System.Drawing.Size(184, 56); + this.btnExample1.Size = new System.Drawing.Size(169, 56); this.btnExample1.TabIndex = 1; this.btnExample1.Text = "1"; this.btnExample1.UseVisualStyleBackColor = true; @@ -58,9 +58,9 @@ private void InitializeComponent() // // btnExample2 // - this.btnExample2.Location = new System.Drawing.Point(244, 210); + this.btnExample2.Location = new System.Drawing.Point(248, 211); this.btnExample2.Name = "btnExample2"; - this.btnExample2.Size = new System.Drawing.Size(184, 56); + this.btnExample2.Size = new System.Drawing.Size(189, 56); this.btnExample2.TabIndex = 1; this.btnExample2.Text = "2"; this.btnExample2.UseVisualStyleBackColor = true; @@ -68,12 +68,13 @@ private void InitializeComponent() // // btnExample3 // - this.btnExample3.Location = new System.Drawing.Point(434, 210); + this.btnExample3.Location = new System.Drawing.Point(443, 211); this.btnExample3.Name = "btnExample3"; - this.btnExample3.Size = new System.Drawing.Size(184, 56); + this.btnExample3.Size = new System.Drawing.Size(175, 56); this.btnExample3.TabIndex = 1; this.btnExample3.Text = "3"; this.btnExample3.UseVisualStyleBackColor = true; + this.btnExample3.Click += new System.EventHandler(this.btnExample3_Click); // // Form1 // diff --git a/LINQ_TO_SQL_EXAMPLE/Form1.cs b/LINQ_TO_SQL_EXAMPLE/Form1.cs index 09a4b2d..34a9242 100644 --- a/LINQ_TO_SQL_EXAMPLE/Form1.cs +++ b/LINQ_TO_SQL_EXAMPLE/Form1.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Data.Entity.SqlServer; using System.Drawing; using System.Linq; using System.Text; @@ -36,7 +37,7 @@ private void btnExample1_Click(object sender, EventArgs e) #region Linq to SQL var product = from x in db.Products - where x.UnitsInStock > 50 && x.UnitsInStock < 8 + where x.UnitsInStock > 50 && x.UnitPrice < 20 orderby x.ProductName select new { @@ -78,6 +79,36 @@ orderby x.EmployeeID #endregion } + private void btnExample3_Click(object sender, EventArgs e) + { + #region Linq To Entity + dataGridView1.DataSource = db.Employees + .Where(x => SqlFunctions.DateDiff("Year", x.BirthDate, DateTime.Now) > 50 && x.City == "London") + .Select(x => new + { + Ad = x.FirstName, + Soyad =x.LastName, + Unvan = x.TitleOfCourtesy, + + + }).ToList(); + + #endregion + #region Linq To Sql + var Employees = from emp in db.Employees + where emp.City == "London" && SqlFunctions.DateDiff("Year", emp.BirthDate, DateTime.Now) > 50 + select new + { + Ad = emp.FirstName, + Soyad = emp.LastName, + Unvan = emp.TitleOfCourtesy, + Yas = SqlFunctions.DateDiff("Year", emp.BirthDate, DateTime.Now) + + }; + #endregion + + } + } }