h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

extern -- C# Keyword

extern -- C# Keyword

  •  The extern modifier is used to declare a method that is implemented externally.
  • A common use of the extern modifier is with the DllImport attribute when you are using Interop services to call into unmanaged code.
  • In this case, the method must also be declared as static, 

[DllImport("<dll Name>.dll")]
private static extern void <dll Method Name>();

const -- C# Keyword

const  -- C# Keyword
  • You use the const keyword to declare a constant field or a constant local.
  •  Constant fields and locals aren't variables and may not be modified.
  •  Constants can be numbers, Boolean values, strings, or a null reference.
const <Data Type> <Var Name> = <Set Value>;

Protected -- C# Keyword

Protected  -- C# Keyword:


  • The protected keyword is a member access modifier.
  • A protected member is accessible within its class and by derived class instances.

 protected <Data Type> <Variable Name>;

async -- C# Keyword

async  -- C# Keyword


  • This Keyword is implemented from VS 2012.
  •         Use the async modifier to specify that a method, lambda expression, or anonymous method is asynchronous.
  •         If you use this modifier on a method or expression, it's referred to as an async method.

public async Task<int> ExampleMethodAsync()
{
    // . . . .

}

in -- C# Keyword

in -- C# Keyword


  •    This Keyword is implemented from VS 2010.
  •    The in keyword specifies that the type parameter is contravariant.
  •    You can use the in keyword in generic interfaces and delegates.

// Contravariant interface.

interface <Interface Name><in A> { }

Insert ,Update ,Delete and Display in Datagridview using LINQ To SQL in C#.Net

Insert ,Update ,Delete and Display in Datagridview using LINQ To SQL in C#.Net

Create tables in SQL server
tbl_department_master
depId  int -- Primary Key -- Set Identify is true
DepName -- varchar(Max)

tbl_Position_Master
PatId int -- Primary key
Patname-- varchar(Max)

Add LINQ To SQL in the your project
Go To Server Explore
Add Data Connection
Drag Tables into LIQToSQL Class
Create user Control

Add User Control in your Project.
Add Datagridview and Two buttons on the User Control
Declare Variables ,Data Context  and Events
 DataClasses1DataContext objDC = null;
 tbl_Department_Master objDM = null;
 tbl_Position_Master objPM = null;
public event EventHandler SaveClicked;
public event EventHandler CloseClicked;
/// To Display Data
 public void Displaydata(string mode)
        {
            switch (mode)
            {
                case "Department":
                    DisplayData("Department");
                    break;
                case "Position":
                    DisplayData("Position");
                    break;
            }
        }
 private void DisplayData(string mode)
        {
            objDC = new DataClasses1DataContext();
            switch (mode)
            {
                case "Department":
                    var query = from q in objDC.tbl_Department_Masters
                                select q;
                    dataGridView1.DataSource = query;
                    break;
                case "Position":
                    var Posquery = from Pq in objDC.tbl_Position_Masters
                                   select Pq;
                    dataGridView1.DataSource = Posquery;
                    break;
            }        
        }
/// Delete Data
 private void DeleteData(string mode)
        {
            objDC = new DataClasses1DataContext();
            switch (mode)
            {
                case "Department":
                    objDM = new tbl_Department_Master();
                    if (objDM != null)
                    {
                        var Delet = from d in objDC.tbl_Department_Masters
                                    select d;
                        foreach (var details in Delet)
                        {
                            objDC.tbl_Department_Masters.DeleteOnSubmit(details);
                        }
                        objDC.SubmitChanges();
                    }
                    break;
                case "Position":
                    objPM = new tbl_Position_Master();
                    if (objPM != null)
                    {
                        var Delet = from d in objDC.tbl_Position_Masters
                                    select d;
                        foreach (var details in Delet)
                        {
                            objDC.tbl_Position_Masters .DeleteOnSubmit(details);
                        }
                        objDC.SubmitChanges();
                    }
                    break;
            }
        }
/// Save Data
public void SaveData(string mode)
        {
            switch (mode)
            {
                case "Department":
                    DeleteData("Department");
                    objDC = new DataClasses1DataContext();
                    for (int index = 0; index < dataGridView1.Rows.Count - 1; index++)
                    {
                        objDM = new tbl_Department_Master();
                        objDM.depId = Convert.ToInt32(dataGridView1.Rows[index].Cells[0].Value);
                        objDM.DepName = Convert.ToString(dataGridView1.Rows[index].Cells[1].Value);
                        objDC.tbl_Department_Masters.InsertOnSubmit(objDM);
                        objDC.SubmitChanges();
                    }
                    DisplayData("Department");
                    break;
                case "Position":

                    DeleteData("Position");
                    objDC = new DataClasses1DataContext();
                    for (int index = 0; index < dataGridView1.Rows.Count - 1; index++)
                    {
                        DataGridViewRow objRowIndex = new DataGridViewRow();
                        objPM = new tbl_Position_Master();
                        objPM.PatId = Convert.ToInt32(dataGridView1.Rows[index].Cells[0].Value);
                        objPM.Patname = Convert.ToString(dataGridView1.Rows[index].Cells[1].Value);
                        objDC.tbl_Position_Masters.InsertOnSubmit(objPM);
                        objDC.SubmitChanges();
                    }
                    DisplayData("Position");
                    break;
            }
        }

Call this User Control in your form:

Add the code in your code Page

private void DisplayData(string mode)
        {
          switch (mode)
            {
                case "Department":
                    ucDepartment1.Displaydata("Department");
                    break;
                case "Position":
                    ucDepartment1.Displaydata("Position");
                    break;
            }

        }

        private void FrmDepartment_Load(object sender, EventArgs e)
        {
            DisplayData("Position");
        }

        private void ucDepartment1_Load(object sender, EventArgs e)
        {

        }

        private void ucDepartment1_CloseClicked(object sender, EventArgs e)
        {
            ((Form)this.TopLevelControl).Close();
        }

        private void ucDepartment1_SaveClicked(object sender, EventArgs e)
        {
            ucDepartment1.SaveData("Position");

        }

do -- C# Keyword

do -- C# Keyword

  •   The do statement executes a statement or a block of statements repeatedly until a specified expression evaluates to false.
  •       The body of the loop must be enclosed in braces, {}, unless it consists of a single statement.
  •       In that case, the braces are optional.
        do
        {
              ///Write your Code        

        } while ();

Abstract -- C# Keywords

Abstract Classes and Abstract Methods in C#.NET

Abstract Classes:

  •   Provide default functionality to its sub classes.
  •   Contain methods with complete implementation, besides abstract methods.
  •   Contains at least one abstract method, then the class must be declared as abstract class.


//Abstract class
    abstract class <Class Name>
    {

        protected float <Var Name>;

        //Abstract methods can have only declarations
        public abstract <DataType> <Method Name>();
         ///Method with Paramenter
        public abstract <DataType> <Method Name>(<DataType> obj);

    }

class  <Class Name(child Class)> : <Class Name(Parent Name)>
{
        public Override <DataType> <Method Name>();
{
/// Write your Code
}

        public Override <DataType> <Method Name>(<DataType> obj);
{
/// Write your Code
}

}

Tips to improve Entity Framework Performance

Tips to improve Entity Framework Performance


  • Avoid to put all the DB Objects into One Single Entity Model
  • Disable change tracking for entity if not needed
  • Use Pre-Generating Views to reduce response time for first request
  • Avoid fetching all the fields if not required
  • Choose appropriate Collection for data manipulation
  • Use Compiled Query wherever needed
  • Retrieve only required number of records
  • Avoid using Contains
  • Avoid using Views
  • Debug and Optimize LINQ Query

ADO.NET Entity Framework Version

ADO.NET Entity Framework Version

Version : 3.5
  This release provided basic O/RM support using the Database first development.
Version: 4.0

  • Model-first development
  • POCO support
  • Lazy Loading
  • T4 Code Generation

Version :4.1

  • Code First development
  • Introduced DbContext API
  • Data Annotations and Fluent API Validation

Version: 4.2
The EF 4.2 release included the bug fixes to EF 4.1
Version: 4.3

  • Code First Migrations
  • Automatic Migrations

Version 5.0

  • Enum Support in Code First and EF Designer
  • Spatial Data Types in Code First and EF Designer
  • Table-Valued Functions
  • Multiple Diagrams per Model

Version 6.0:

  • Async Query and Save
  • Code-Based Configuration
  • Dependency Resolution
  • Interception/SQL logging
  • Improved Connection Management
  • Improved Transaction Support