Simply LINQ: What,Why and How.
Dec24

Simply LINQ: What,Why and How.

Welcome to CodeSpread! What is LINQ? LINQ is Language-Integrated Query (LINQ). It is primarily an extension to the language’s capability where it adds query expressions which processes objects and data. It is a one stop solution to all the query processing as now there is no need to learn a different query language for each type of data source: SQL databases, XML documents etc. Why LINQ? Type safe. IntelliSense support. Tables are available as classes. SQL generated is well structured and optimized. Targets Business rules. Easy to debug with the visual studio’s debugger. Easy to deploy as being a part of DLL. LINQ to SQL parameterizes input so better security. And,best of all, SIMPLE. An example: var Employee= from emp in Employees where emp.name="CodeSpread" select emp; Let’s see the flow, First the ‘from’ clause points to the data source which is ‘Employees’. Next, ‘where’ specifies the filter which is the employee name. Lastly, ‘select’ statement returns the result set. There are three main components of LINQ. Standard Query Operators Language Extensions LINQ Providers Standard Query Operators: The standard query operators can be simply referred to as methods in LINQ .There are two sets of LINQ standard query operators, Operates on objects of type IEnumerable and, Operates on objects of type IQueryable. var result= from emp in Employees orderby emp.empid select emp.name; But it doesn’t look like method, let’s write it again. var result= Employees. Select(emp=>emp.name).OrderBy(emp=> emp.empid); Looks good now. Both of the above examples just vary in syantax. There are many other Standard Query Operators available which we will enlist in a future article. Language Extensions: Implicitly Typed Variables. Anonymous Types. Object Initializers. Lambda Expressions LINQ Providers: These are data source-specific implementations for ex: in-memory object collections, Microsoft SQL Server databases, ADO.NET datasets and XML documents. LINQ to Objects – Executes a LINQ query against a collection of objects For an in-memory object collections like arraylist of employees, var result= from emp  in empList where emp.name="CodeSpread" select emp; LINQ to XML – Executes an XPATH query against XML documents. XElement root= XElement.Load("\..\Employees.xml"); IEnumerable employee= root.Elements(); LINQ to SQL – Executes LINQ queries against Microsoft SQL Server. For a Database called company and table called customers. IQueryable customer = from cust in company.Customers where cust.name== "CodeSpread"  select cust; LINQ to ADO.NET datasets– Executes LINQ queries against ADO.NET DataSets. Same example as above where the data is queried from a dataset instead of directly from a...

Read More
23 Dec: Must Read Codes [11-15]
Dec23

23 Dec: Must Read Codes [11-15]

We are sharing few must read codes/concepts which are required now and then. Each of these codereads doesn’t require a full length descriptive article so combining them into groups of five. CodeReads #11, We have two properties in CSS to hide the elements but there is a difference in their behavior such as if we use ‘Visibility:Hidden;’ : element will NOT be visible but will take its space on the page. if we use ‘Display:None;’ : element will NOT be visible and also in addition to that, will NOT take up space on the page. This makes page lighter. fbsource:https://www.facebook.com/codespread/posts/554571687899390 CodeReads #12, A jagged array is an array of arrays and is declared as string[][] jagarray; For example: string[2][4] jagarray; It is jagged array where first square bracket is a one-dimensional array and contains two arrays where each one of them internally contains 4 arrays. A multidimensional array is declared as string[ , ] mularray; For example: string[2,4] mularray; It is multidimensional array where ‘,’ separates it to two dminesions containing 2 and 4 elemnts respectively. fbsource: https://www.facebook.com/codespread/posts/554833934539832 CodeReads #13, To Count number of tables in a SQL Server database USE DB_NAME SELECT COUNT(*) from information_schema.tables WHERE table_type = ‘base table’ fbsource:https://www.facebook.com/codespread/posts/561133753909850 CodeReads #14, Garbage collection occurs when one of the following conditions is true: 1.The system has low physical memory. 2. The memory that is used by allocated objects on the managed heap surpasses an acceptable threshold. This means that a threshold of acceptable memory usage has been exceeded on the managed heap. This threshold is continuously adjusted as the process runs. 3. The GC.Collect method is called. In almost all cases, you do not have to call this method, because the garbage collector runs continuously. This method is primarily used for unique situations and testing. Source:MSDN fbsource: https://www.facebook.com/codespread/posts/577240208965871 CodeReads #15, A property is classified according to the accessors used as follows: 1.A property with a get accessor only is called a read-only property. You cannot assign a value to a read-only property. 2.A property with a set accessor only is called a write-only property. You cannot reference a write-only property except as a target of an assignment. 3.A property with both get and set accessors is a read-write property. Source:MSDN...

Read More
20 Dec: Must Read Codes [6-10]
Dec20

20 Dec: Must Read Codes [6-10]

We are sharing few must read codes/concepts which are required now and then. Each of these codereads doesn’t require a full length descriptive article so combining them into groups of five. CodeReads #6, What is the difference between Dispose and Finalize? #Point 1, Dispose is used to release unmanaged resources in a deterministic fashion, like we know when to release the resource. Finalize method is also used for the purpose of releasing resources but in non-deterministic fashion like we cannot be sure as when Garbage Collector will collect the resource. #Point 2 , Finalize method has a performance drawback due to the Garbage Collector as there will be two iterations of Garbage Collector and override operation. fbsource :https://www.facebook.com/codespread/posts/550605628295996 CodeReads #7, Garbage Collector maintains managed objects in “generations.” The generation indicates the lifetime of an object like objects having short life are stored in lower generations as GC runs much more frequently to clean up objects in the lower generations. The more the objects survive a GC cleanup, the more the chances that these objects will get moved to higher generations. There will be few GC swipes on higher generations and also that will happen only if lower generations have no space left. When we talk about generations, we talk about physical memory locations divided,managed and allocated to each generation number. fbsource: https://www.facebook.com/codespread/posts/550949951594897 CodeReads #8, .data() : Store arbitrary data associated with the matched elements or return the value at the named data store for the first element in the set of matched elements. For more information: http://api.jquery.com/data/ fbsource: https://www.facebook.com/codespread/posts/370621346386549 CodeReads #9, Elements of a UML Class Diagram are: Class Operations Relationships -Associations -Generalization -Dependency -Realization Constraint Rules and Notes fbsource: https://www.facebook.com/codespread/posts/552364564786769 CodeReads #10, Scaffolding is a technique in which the programmer may write a specification that describes how the application database may be used. With the help of this concept,programmer can create a functional Web site for viewing and editing data based on the schema of the data. ASP.NET Dynamic Data supports scaffolding. Refer the below link. For more information: http://msdn.microsoft.com/en-IN/library/ee845452%28v=vs.100%29.aspx fbsource:...

Read More
19 Dec: Must Read Codes [1-5]
Dec19

19 Dec: Must Read Codes [1-5]

We are sharing few must read codes/concepts which are required now and then. Each of these codereads doesn’t require a full length descriptive article so combining them into groups of five. CodeReads #1, Usage of ‘this’ keyword in C#. To qualify members hidden by similar name. To have an object pass itself as a parameter to other methods. To have an object return itself from a method. To declare indexers. To declare extension methods. To pass parameters between constructors. To internally reassign value type (struct) value. fbsource: https://www.facebook.com/codespread/posts/544740368882522 CodeReads #2, ISNULL and COALESCE though equivalent, can behave differently. An expression involving ISNULL with non-null parameters is considered to be NOT NULL, while expressions involving COALESCE with non-null parameters is considered to be NULL. fbsource: https://www.facebook.com/codespread/posts/545045568852002 CodeReads #3, Regular Cast: string str= (string) strToCast; Method Call: string str= strToCast.ToString(); Safe Cast: string str= strToCast as string; fbsource: https://www.facebook.com/codespread/posts/545045568852002 CodeReads #4, Control State maintains the behavior of the controls whereas View State maintains the content of the controls. Also, Control State is available even though View State for the control is disabled. fbsource: https://www.facebook.com/codespread/posts/547846855238540 CodeReads #5, In javascript, Body.Onload() event occurs only after the DOM has been loaded, plus all associated resources like images, flash etc are also completely loaded. $(document).ready() occurs when the DOM has been loaded but associated resources like images, flash etc may be pending. There can be multiple document.ready() in a page but Body.Onload() event will be only one. fbsource:...

Read More
Few lines about Static code analysis
Dec18

Few lines about Static code analysis

Static code analysis We divide the term into two parts: Static+code analysis. Static in programming can be referred to as non-running/non-dynamic and code analysis is a process where the code is analyzed for any vulnerability, also it had been always used for possible improvements. So, we can say that, it is a process of detecting errors and defects in software’s source code in a static state where the entire code base is analyzed and code flaws are exposed. Advantages: This process covers whole code base and find vulnerabilities in the code at the exact location. This process can locate anti-patterns. This process can identify performance issues and also suggest improvements. Limitations: Automated tools may not support all programming languages or compilers. Automated tools produce false positives and false negatives. Manual review or Personal review is always considered to be more beneficial and reliable than a tool. We have many Static code analysis tools available like StyleCop, FxCop etc. and using them can always take off the burden from reviewer’s shoulders...

Read More
Few lines on Exploratory testing
Dec16

Few lines on Exploratory testing

What is Exploratory testing? Exploratory testing by far is an approach to run and learn where testers do not create test cases beforehand. They usually gets acquainted with the system first. It provides a learning opportunity to the testers where they need to think before they begin creating or applying any test case. This is more of an ad-hoc approach where testers get a free hand on the system. Plus, this learning helps to write the test cases on the run. Why Exploratory testing? What is the need? Need is the current trend which says to identify bugs before the actual testing. Current trend emphasizes on the learning than the actual implementation. It is more about the Improvement which can be brought into the system beforehand. Exploratory testing is run by the data in hand and not the scripts. This approach widens the scope of testing. It helps the testers to understand the system, explore the system and reach the unexplored territories. With Exploratory testing, less preparation is required, important bugs are found quickly, and provides space for run-time learning. How Exploratory testing is different from Scripted testing? Scripted testing has many advantages like re usability, compliance and result oriented but when we compare it with exploratory testing; we know that, with scripted testing, testers always have test cases ready with them before they begin the testing. This limits their scope and they just need to compare the actual results with expected results. There is no dynamic learning and always a chance of random and sudden tweaks/ improvement in the testing approach. Conclusion: Both the approaches have their own advantages and shortcomings and both approaches exhibits same efficiency and result fulfillment. But we know, in some way, exploratory testing empathize learning and...

Read More
Page 1 of 16123456...Last »