LINQ Assignment Help

Assignment Help: >> ASP.Net Programming >> LINQ

LINQ:

Most services are data-centric and most of these data repositories are nevertheless, relational databases. Over the years developers and designers have prepared applications lied on object models.

These objects were dependable for connecting to the data access components - called the data access level (DAL). There are however, two effects to reflect on:

  • All the data wanted in an application are not stored in the same resource. The source should be a relation database, some business objects, XML file, or on web application.
  • Accessing in-memory object is less expensive and simpler than accessing data from a database or XML file.
  • The data contacted are not used directly, but requirements to be sorted, grouped, ordered, altered etc.

So if there is one tool that creates all kinds of data access simple, that allows joining facts from such unlike data sources and do standard data processing operations, in few lines of codes, it would be of huge help.

LINQ or Language-Integrated Query is such a device. LINQ is set of extensions to the .Net Framework 3.5 and its handled languages that sets the query as an object. It describes a common syntax and a programming representation to query different kinds of data using a common language.

The relational operators like Project, Join, Select, Group, Partition, Set operations etc., are derived in LINQ and the C# and VB compilers in the .Net framework 3.5, which gives the LINQ syntax creates it possible to work with a configured data save without taking to ADO.Net.

For example querying the Customers table in the Northwind database, by means of LINQ query in C#, the code could be:

var data = from c in dataContext.Customers

where c.Country == "Spain"

select c;

Where:

  • The 'from' keyword logically loops from side to side the contents of the collection.
  • The expression with the 'where' keyword is calculated for each object in the collection.
  • The 'select' statement chooses the calculated object to add to the list being returned.
  • The 'var' keyword is for variable declaration. Since the exact type of the examined object is not known, it shows that the information will be related dynamically.

LINQ query may be related to any data-bearing class that inherits from IEnumerable<T>, here T is any data type, for example List<Book>.

Let us look at an example to identify with the idea. The example uses the subsequent class: Books.cs

public class Books

{

   public string ID {get; set;}

   public string Title { get; set; }

   public decimal Price { get; set; }

   public DateTime DateOfRelease { get; set; }

 

   public static List<Books> GetBooks()

  {

     List<Books> list = new List<Books>();

     list.Add(new Books { ID = "001",

     Title = "Programming in C#",

     Price = 634.76m,

     DateOfRelease = Convert.ToDateTime("2010-02-05") });

 

     list.Add(new Books { ID = "002",

     Title = "Learn Jave in 30 days",

     Price = 250.76m,

     DateOfRelease = Convert.ToDateTime("2011-08-15") });

 

     list.Add(new Books { ID = "003",

     Title = "Programming in ASP.Net 4.0",

     Price = 700.00m,

     DateOfRelease = Convert.ToDateTime("2011-02-05") });

 

     list.Add(new Books { ID = "004",

     Title = "VB.Net Made Easy",

     Price = 500.99m,

     DateOfRelease = Convert.ToDateTime("2011-12-31") });

 

     list.Add(new Books { ID = "005",

     Title = "Programming in C",

     Price = 314.76m,

     DateOfRelease = Convert.ToDateTime("2010-02-05") });

 

     list.Add(new Books { ID = "006",

     Title = "Programming in C++",

     Price = 456.76m,

     DateOfRelease = Convert.ToDateTime("2010-02-05") });

 

     list.Add(new Books { ID = "007",

     Title = "Datebase Developement",

     Price = 1000.76m,

     DateOfRelease = Convert.ToDateTime("2010-02-05") });

     return list;

  }

 

}

The web page using that class has a simple label control, which will show the titles of the books. The Page_Load event makes a list of books and gives the titles by using LINQ query:

public partial class simplequery : System.Web.UI.Page

{

   protected void Page_Load(object sender, EventArgs e)

   {

      List<Books> books = Books.GetBooks();

      var booktitles = from b in books select b.Title;

 

      foreach (var title in booktitles)

         lblbooks.Text += String.Format("{0} <br />", title);

   }

}

When the page is executed, the label will shown the results of the query:

2232_linq.png

The above LINQ expression:

var booktitles =

from b in books

select b.Title;

Is equivalent to the subsequent SQL query:

SELECT Title from Books

LINQ Operators:

Apart from the operators used so far, there are various other operators, which shown all query clauses. Let us look at some of the clauses and operators.

The Join clause:

The 'join clause' in SQL is needed for joining two data tables and shows a data set containing columns from both the tables. LINQ is also capable of that. To select this, include another class named Saledetails.cs in the given project:

public class Salesdetails

{

   public int sales { get; set; }

   public int pages { get; set; }

   public string ID {get; set;}

 

   public static IEnumerable<Salesdetails> getsalesdetails()

   {

      Salesdetails[] sd =

      {

      new Salesdetails { ID = "001", pages=678, sales = 110000},

      new Salesdetails { ID = "002", pages=789, sales = 60000},

      new Salesdetails { ID = "003", pages=456, sales = 40000},

      new Salesdetails { ID = "004", pages=900, sales = 80000},

      new Salesdetails { ID = "005", pages=456, sales = 90000},

      new Salesdetails { ID = "006", pages=870, sales = 50000},

      new Salesdetails { ID = "007", pages=675, sales = 40000},

      };

      return sd.OfType<Salesdetails>();

   }

}

include the codes in the Page_Load event handler to query on both the tables using the link clause:

protected void Page_Load(object sender, EventArgs e)

{

   IEnumerable<Books> books = Books.GetBooks();

   IEnumerable<Salesdetails> sales =

                       Salesdetails.getsalesdetails();

   var booktitles = from b in books

             join s in sales

             on b.ID equals s.ID

             select new { Name = b.Title, Pages = s.pages };

   foreach (var title in booktitles)

      lblbooks.Text += String.Format("{0} <br />", title);

}

The resulted Page:

2472_linq1.png

The Where clause:

The 'where clause' allows adding up some conditional filters to the query. For example, if you wish to see the books, where the number of pages are more than 500, modify the Page_Load event handler to:

var booktitles = from b in books

          join s in sales

          on b.ID equals s.ID

          where s.pages > 500

          select new { Name = b.Title, Pages = s.pages };

The query returns simply those rows, where the number of pages is more than 500:

1484_linq2.png

The Orderby and Orderbydescending clauses:

These clauses let sorting the query results. To query the titles, price of the book, sorted by the price, and number of pages write the subsequent code in the Page_Load event handler:

var booktitles = from b in books

                 join s in sales

                 on b.ID equals s.ID

                 orderby b.Price

                 select new { Name = b.Title,

                 Pages = s.pages, Price = b.Price};

The returned tuples are:

247_linq3.png

The Let clause:

The let clause gives a variable and assigning it a value evaluated from the data values. For example, to examine the total sale from the above two sales, you require to check:

TotalSale = Price of the Book * Sales

To achieve this, add the following code snippets in the Page_Load event handler:

The let clause allows describing a variable and related it a value added from the data values. For example, to evaluated the total sale from the above two sales, you require to calculate:

var booktitles = from b in books

     join s in sales

     on b.ID equals s.ID

     let totalprofit = (b.Price * s.sales)

     select new { Name = b.Title, TotalSale = totalprofit};

The resultant query page looks like:

362_linq4.png

 

Email based ASP.Net assignment help - homework help at Expertsmind

Are you searching ASP.Net expert for help with LINQ questions?  LINQ topic is not easier to learn without external help?  We at www.expertsmind.com offer finest service of ASP.Net assignment help and ASP.Net homework help. Live tutors are available for 24x7 hours helping students in their LINQ related problems. Computer science programming assignments help making life easy for students. We provide step by step LINQ question's answers with 100% plagiarism free content. We prepare quality content and notes for LINQ topic under ASP.Net theory and study material. These are avail for subscribed users and they can get advantages anytime.

Why Expertsmind for assignment help

  1. Higher degree holder and experienced experts network
  2. Punctuality and responsibility of work
  3. Quality solution with 100% plagiarism free answers
  4. Time on Delivery
  5. Privacy of information and details
  6. Excellence in solving ASP.Net queries in excels and word format.
  7. Best tutoring assistance 24x7 hours

 

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd