Linq query for Database Operation using ADO.NET Entity Framework:-



1)  The query for Data Selection:-

       var variablename =  from c in db.tablename select c    in SQL  (select * from tablename)

        c is the identifier, the table name will be in the plural name

        var variablename = db.tablename()

     
        Select a Particular Column or Projection LINQ Query

        var data = from c in db  select new {column1 = c.columnname,column2=c.columnname }

       var data = from c in db.Students select new {rno=c.rno,sname=c.sname }

       IN SQL this query will be select rno,sname from Stduent


2)  Query for Data Selection based on Condition:-

    2.1)  var s = from c in db.tablename where c.columnname==value select c;
   
     in SQL this query will be select * from tablename where c.columnname=value

  2.2)    var s = from c in db.tablename where c.columnname==value && c.columnname2==value Select c;
     in SQL this query will be  select * from tablename where c.columnname1=value and                  c.columnname2=value

2.3)    var s = from c in db.tablename where c.columnname==value || c.columnname2==value select c;

in SQL query this will be Select *  from tablename where columnname1=value or columnname2=value


3)  For Data Insertion :-
                                                //db is the Object of database entity class
      db.tablename.Add(ref);   //  it is the reference of Model Class
      db.SaveChanges()    // It is used to reflect data of an application to database server.

4)  For Data Updation:- 

    db.Entry(ref).State = EnityState.Modified;   // ref is the reference of Model Class Object
    db.SaveChanges()

5)   For Data Deletion:-
      db.tablename.Remove(ref);   //ref is the reference of Model Class Object
      db.SaveChanges()

 6)  For Find Record:-

       var variablename = db.tablename.Find(ref);
   


   




Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post