" Live as if you were to die tomorrow. Learn as if you were to live forever.. "
- Mahatma Gandhi

Default behaviour of the entity datamodel while setting the default value of a field in SQL’s field designer

Posted on November 24th, 2015 by Swati Gupta

What should be the default behavior of LINQ-to-Entities while setting the default value of a field in SQL’s field designer ? Sometimes it’s difficult to come up with a topic that we feel inspired to write about. I am writing about the problem I encountered while working with entity datamodel. After discussing with the team […]

List directory files of specific size (Using C# and LINQ)

Posted on November 23rd, 2015 by Satyadeep Kumar

The following code can be used to extract files that are greater than 1MB under any specific directory (using LINQ). private static void GetFiles(string Path) { try { DirectoryInfo directory = new DirectoryInfo(Path); FileInfo[] files = directory.GetFiles(“*.*”, SearchOption.AllDirectories); var query = from file in files where file.Length > 1024*1024 select “File Name:”+ file.Name + ” […]

How to get list of Local and Network Printers

Posted on November 23rd, 2015 by Digvijay Verma

To get the list of printer queue we call the method GetPrintQueues. This method has a number of signatures for populating different kind of printers. PrintServer localPrintServer = new PrintServer();   If you do not pass any argument  (i.e localPrintServer.GetPrintQueues()), it will just return the printer queue attached directly to your machine. But as we […]

Iterate thorugh collection for unique values only (using LINQ and C#)

Posted on November 23rd, 2015 by Satyadeep Kumar

Sometimes we work with collections that contain duplicate data and we just want to iterate over unique values inside the collection. To iterate only through unique values, we generally have to use for-loop and check (compare) each and every data inside the collection for duplicate entries, which is a bit tedious task. However, if you are using Linq it becomes […]

Check The Duplicate Files Inside A Folder

Posted on November 23rd, 2015 by Srikant Biswal

In our projects, some times we need to compare files and delete or move the duplicate files to another folder.LINQ (Language Integrated Query) is a Microsoft programming model and methodology that essentially adds formal query capabilities into Microsoft .NET-based programming languages. LINQ will help to check the duplicates files and return the list of duplicate […]

Access database table and Sql database table using Linq

Posted on November 23rd, 2015 by Tapaswini Mohanty

Problem: We need to join a table from an access database and another from an sql database and display the result in a gridview in .net. Solution: STEP 1: Add a dataset to the project. Lets name the DataSet as DSEmployee. STEP 2: Add new connections in server explorer for the access database and sqlserver […]

How to generate data in XML format using LINQ

Posted on November 23rd, 2015 by PRADEEP PENTAPATI

To create XML using LINQ as follows Step 1: XElement class takes care of converting the LINQ query resultant into data in XML format. So, declare the name space “using System.Xml.Linq;” Step 2: Now, the LINQ query should be written in the below format: DataClassesDataContext dlDC = new DataClassesDataContext(); var inventory = new XElement(“InventoryINFO”, from […]

How to get distinct rows from a list using LINQ

Posted on November 23rd, 2015 by Mritunjay Kumar

How to get distinct rows from a list using LINQ: Think about a situation when records in list are something like below: Employee1: EmployeeId=1, Name=”Name1″, EmployeeType=2; Employee2: EmployeeId=2, Name=”Name2″, EmployeeType=3; Employee3: EmployeeId=3, Name=”Name3″,  EmployeeType=1; Employee4: EmployeeId=4, Name=”Name4″,  EmployeeType=2; Employee5: EmployeeId=5, Name=”Name5″,  EmployeeType=3; And we want the records of Employee1, Employee2, Employee3 (which are actually distinct […]