background preloader

Linq

Facebook Twitter

LINQ over C# project. Genome > Home. Linq.js - LINQ for JavaScript. Zip operator in Linq with .NET 4.0 - DotNetJaps. Microsoft .NET framework 4.0 is having many features that make developers life very easy. Its also provides some enhancement to Linq also. I just found a great operator called Zip which merge the sequence of two entities. Here is the explanation of Zip Operator from MSDN. “The method merges each element of the first sequence with an element that has the same index in the second sequence. Here is the simple console application for the zip.

C#, using GeSHi 1.0.8.8 Parsed in 0.021 seconds at 44.60 KB/s Here is the output of following code as expected. Hope this will help you. C# 4.0 in a Nutshell - LINQBridge. LINQBridge You might already have discovered that LINQ is addictive: once you're accustomed to solving problems through slick functional queries, it really hurts being forced back to the imperative style of C# 2.0! LINQ's query operators are implemented from .NET Framework 3.5.

And here lies a difficulty: your clients might have only Framework 2.0 installed on their machines. So what does this mean if you want to code in C# 3.0 and write LINQ queries? The good news is that there is a solution. Visual Studio 2008's multi-targeting feature LinqBridge.dll (a 60KB assembly) With Studio's multi-targeting and LINQBridge, you'll be able to write local (LINQ to Objects) queries using the full power of the C# 3.0 compiler—and yet your programs will require only Framework 2.0. LINQBridge is a reimplementation of all the standard query operators in Framework 3.5's Enumerable class. How does it work? But—you might ask—don't LINQ queries depend on Framework 3.5? How to use LINQBridge Licensing Download. SP 2010: Getting started with LINQ to SharePoint in SharePoint 2010 - Tobias Zimmergren's thoughts on development.

Author: Tobias Zimmergren | | @zimmergren In SharePoint 2010 you now have the ability to use LINQ syntax to fetch items from your lists instead of using the "traditional" approach of CAML queries. (Including SPSiteDataQuery and SPQuery objects) In this article I will give you a brief introduction to how you can get started using LINQ queries in SharePoint, also known as LINQ to SharePoint. As a prerequisite to this article, I’m going to imply that you know what LINQ is and how to write basic LINQ queries in any .NET application already. I’m not going to dive into the details about LINQ or the syntax itself here – please see MSDN for that! In order to work with LINQ in SharePoint 2010, we need use a tool called SPMetal.exe which resides in the 14bin folder.

Noteworthy: LINQ to SharePoint queries are translated to proper CAML queriesCAML queries are in turn later translated to SQL queries SPMetal.exe These are the required steps to get hooked up: LINQ to SharePoint. i4o - Indexed LINQ. Specifications in C# 3.0 - Windows Live. This is the last of my posts on LINQ before switching over to Beta2; I’m playing catch-up but be aware that some things will have changed. I will post any changes for Beta 2 to both this and Being Ignorant in LINQ to SQL as time permits. What are Specifications? Specification is a design pattern authored by Martin Fowler and Eric Evans. If you are not familiar with specifications then you can read more about them in Eric Evans book Domain Driven Design, or just read this comprehensive paper.

If you are not sure what Specifications are, you might want to read that before you read this. For those of you who just want a refresher, or who do not want to read the article first: a specification is a pattern for expressing a rule which you want to use to test an object. A specification is ultimately used to separate two orthogonal concerns: testing objects and the objects themselves. Instead of writing: customer.IsInSalesRegion("London"); we want to write: Hard Coded Specifications or even the line:

Kirk Evans Blog : Calling SharePoint Lists Web Service Using WCF. WCF makes it easy to call the SharePoint web services using WCF. In this post, I’ll show how to call the Lists.asmx web service and show the few things you need to take into account. Creating the Proxy Just like if you were using ASMX web services, the place to start is to create a reference to the SharePoint Lists.asmx web service. This is done by appending “/_vti_bin/Lists.asmx” to the end of a site name. Now that you know how to choose the appropriate URL, pop open a Visual Studio 2008 project and use the Add Service Reference dialog. You’ve now created the proxy, but you’re not done yet. Authentication Once you’ve created the proxy, the next step is to configure the security to be able to call the service methods. 1: <?

2: <configuration> 3: <system.serviceModel> 4: <bindings> 5: <basicHttpBinding> 6: <binding name="ListsSoap"> 7: <security mode="TransportCredentialOnly"> 8: <transport clientCredentialType="Ntlm" /> 9: </security> 10: </binding> 11: </basicHttpBinding> 12: </bindings> Download details: ADO.NET vNext CTP, August 2006. LINQ provider basics. Learn how to create custom LINQ providers. Introduction LINQ (Language Integrated Query) works as a middle tier between data store and the language environment. From a developer's point of view, it is just a new pattern for querying data from multiple data structures directly in the IDE. Behind the scenes it does a whole lot of tasks like expression processing, validation and calling the right routine to fetch data or build a query to run in SQL Server.

In short, LINQ stands as common query gateway between the language and the data store. Figure 1: LINQ workflow (from language to data store) The purpose of this article is to teach you how to extend this query pattern in order to create your own custom provider. Creating and Executing a Query LINQ is a new level of language abstraction that supports querying virtually any data source - such as SQL, XML and in-memory data structures like Dictionary, List and more. Note that a class must implement IQueryable to be queried by a user. 3. 4. 5. LINQ to SQL Extension: Batch Deletion with Lamb... Batch deletion in the O/R Mapping frameworks is always depressing. We need to query all the entities we want to delete from the database, pass them to the DeleteOnSubmit or DeleteAllOnSubmit methods of DataContext, and finally invoke SubmitChanges to delete the records form database.

In this case, we will cost an additional query and send lots of "DELETE" commands to database. How wasteful! So if we want to make batch deletion with LINQ to SQL, we'll probably execute a SQL command in souce code: ItemDataContext db = new ItemDataContext(); db.ExecuteCommand( "DELETE FROM Item WHERE [CreateTime] < {0}", DateTime.UtcNow.AddMonths(-1)); But in my opinion, it's ugly if we put SQL commands in source code. But batch deletion is one of the exceptions, as I said minutes ago. ItemDataContext db = new ItemDataContext(); db.Items.Delete(item => item.CreateTime < DateTime.UtcNow.AddMonths(-1)); Of course, we could use more complicated expressions to indicate the entities to delete: LINQ &amp; Reflection in C# 3.0 « The Wandering Gli... I posted an article the other day showing you how to exploit the query capabilities of LINQ to do reflection over the attributes on a C# class.

I want to show you how to exploit some of the extension methods in System.Query to make the code even cleaner. I used a method called Members that got all of the members in order of member type (i.e. fields first, properties next and so on). The code looked like this: public static IEnumerable<MemberInfo>Members(this Type t) { foreach (FieldInfo fi in t.GetFields()) yield return fi; foreach (PropertyInfo pi in t.GetProperties()) yield return pi; foreach (MethodInfo mi in t.GetMethods()) yield return mi; foreach (EventInfo ei in t.GetEvents()) yield return ei; } I needed to split the queries into each of the types we required in order to get elements ordered by type.

Well System.Query provides a neater way to do this sort of thing. Foreach (MemberInfo mi in from m in t.GetMembers() orderby m.GetType().Name, m.Name select m) { yield return mi; } David Ebbo&#039;s ASP.NET blog : Dynamic Data at MIX... Yesterday, I gave a talk on ASP.NET Dynamic Data at the MIX 2008 conference. It was a full room, and it was great to see the interest for the technology. What's nice about MIX is that they are making all talks available online within 24 hours.

So you can watch my talk today! Here is the direct link. Note that the build of Dynamic Data that I use in the session is quite a bit newer than the one we made available in December. While a lot of the core concepts remain the same, there are a number of important changes, and I'll describe some of them here: Entity Framework support In addition the Linq To Sql, Dynamic Data now supports Entity Framework.

Folder structure changes In the December CTP, we were using an App_Shared folder, and that name really didn't make much sense. App root global.asax, web.config, site.master, ... Use of ASP.NET Routing to configure URLs In the CTP, Dynamic Data was using a fairly complex web.config section to customize its URLs. Many bug fixes and API renames. ASP.NET Dynamic Data Preview. Solving LINQ&#039;s N-Tier Issues - Bryan Sampica. Ok, so maybe solving is somewhat of a misnomer, but we certainly can combat them with strength and conviction. A little background on the subject first; LINQ has proven to be somewhat of a booger when attempting to work with it in a streamlined development environment when incorporating any sort of N-Tier pattern.

Why you ask should it be a problem...the common answer I've heard many many times is, why should it be any different? You have at the essence of it some pretty simple logical and physical layer guidelines right? It's well known in the industry at this point to create N-Layer app's to solve things like SOC (separation of concerns) and physical or network boundaries.

But what about LINQ....how does it change anything we've done before? Here's the tricky part: LINQ objects, created outside a context are considered unattached - which works great...but the moment you have to refer to an object in relation to it's context you run into major issues. Parallel LINQ: Running Queries On Multi-Core Pr... Parallel LINQ Running Queries On Multi-Core Processors Joe Duffy and Ed Essey THis article is based on the Parallel FX library, which is currently in development. All information herein is subject to change. Multi-core processors are here. Once pervasive mainly in servers and desktop PCs, now multi-core processors are being used in mobile phones and PDAs, resulting in great benefits in power consumption. Responding to the increased availability of multi-processor platforms, Parallel Language Integrated Query (PLINQ) offers an easy way to take advantage of parallel hardware, including traditional multi-processor computers and the newer wave of multi-core processors.

PLINQ is a query execution engine that accepts any LINQ-to-Objects or LINQ-to-XML query and automatically utilizes multiple processors or cores for execution when they are available. From LINQ to PLINQ When people first hear about the PLINQ project, they usually ask: why parallelize LINQ? PLINQ Programming Model And that's it! 10 Tips to Improve your LINQ to SQL Application... Hey there, back again. In my first post about LINQ I tried to provide a brief(okay, bit detailed) introduction for those who want to get involved with LINQ to SQL.

In that post I promised to write about a basic integration of WCF and LINQ to SQL working together, but this is not that post. Since LINQ to SQL is a code generator and an ORM and it offers a lot of things, it is normal to be suspicious about performance of it. These are right up to a certain point as LINQ comes with its own penalties. But there are several benchmarks showing that DLINQ brings us up to %93 of the ADO.NET SQL DataReader performance if optimizations are done correctly. Hence I summed up 10 important points for me that needs to be considered during tuning your LINQ to SQL’s data retrieval and data modifying process: 1 – Turn off ObjectTrackingEnabled Property of Data Context If Not Necessary If you are trying only to retrieve data as read only, and not modifying anything, you don’t need object tracking. Using the IRepository pattern with L...

27th March 2009. It's now a year since I wrote this post. Thanks to some comments by Janus2007 I've realised that it needs updating. I've replaced the code with the current version of the Suteki Shop LINQ generic repository. There are a number of changes in the way it works. The other major change is marking the SubmitChanges methods as obsolete. Please have a look at the Suteki Shop code to see the generic repository in action: LINQ to SQL is a quantum leap in productivity for most mainstream .NET developers. So where is our point of separation between data access and domain? My current project is based on the new MVC Framework. Using System; using System.Linq; using System.Linq.Expressions; using System.Data.Linq; using Suteki.Common.Extensions; namespace Suteki.Common.Repositories public interface IRepository<T> where T : class T GetById(int id); IQueryable<T> GetAll(); void InsertOnSubmit(T entity); void DeleteOnSubmit(T entity); void SubmitChanges(); public interface IRepository itemParameter,

Ben Hall&#039;s Blog: Obtaining table metadata using... One of the posts on the MSDN forum asked how to obtain the type length of a column in the table using Linq, this post will just explain how to obtain this information and some information on the MappingSource object. When linq does the mappings of database to objects, it transforms the DBType (NVarChar) into a CLR Type (String) which means when you are accessing the objects in code, you are accessing them as .Net types hence no simply way to get the underlying DBType.

One way would be to look the information up in the mappings file or the attribute but Dinesh Kulkarni (PM) pointed out an more directly way, in an indirect way. To demonstrate this in code, first we get the MemberInfo type for the column we are interested in for the GetDataMember method. Then we can gain the DBType via the MappingSource. string columnName = “OrderID”;MemberInfo[] mf = Type.GetType(“LinqConsole.Order”).GetMember(columnName); The DBType in this case is “Int NOT NULL IDENTITY”. Post link: Infosys | Microsoft: Group By Many/Multiple Cri... 101 Linq Samples. LINQ IQueryable Toolkit - Home. Fluent Linq to Sql - Home.

Mitsu&#039;s blog : Linq GroupByMany dynamically. Shawn asked me in my last post about GroupByMany how to use it dynamically. The answer is not easy. So here is a new post to answer to this interesting question. First you must learn a few things about being dynamic with linq.There is a very good sample from the C# team (actually we can consider it as a library provided as a sample). ScottGu has post about it here: One of the power of linq is to be checked at compile-time. Now I have added the Dynamic.cs file to my project and I can use a very useful method: DynamicExpression.ParseLambda. Here is a new GroupByMany extension method which accepts a list of strings instead of delegates to define all the groupings.The goal is to call the first GroupByMany method. Now we can write directly: DataContext = customers.GroupByMany("Country", "City"); instead of : DataContext = customers.GroupByMany(c => c.Country, c => c.City);

Mitsu&#039;s blog : Playing with Linq grouping: GroupByMany ? LINQ Extensions - Home. Lazy Computation in C# on MSDN. The Twitter Search API made easy with Linq to X... Linq.