Tag | LINQ Posts

Here's a really short and simple bit of code that has the potential to be a bit of a time-saver. The FindControl method of the Control class is used to find a specific child control of a given parent, searching by ID. This method, however, doesn't search the control hierarchy recursively: it searches the direct children of the specified parent control only. While writing a recursive version of this method is trivial, a rather nice way to make the method reusable is to implement it as an extension ...
To use LINQ To SQL, we need a Data Context object to provide our point of entry. It might be possible to use a System.Data.Linq.DataContext object directly, but its more usual to derive from this class to make a database specific version. Additionally, we need classes to represent our "entities". These define the mapping to the tables (or views) and columns. We could code all this up by hand, but Visual Studio 2008 comes with the grandly named Object Relational Designer that makes short work of this. ...
[Update: This blog post was orignally posted in early 2008, in another blog. Things have changed a little in F#, and Ted Nedward has provided updated information related to this, showing how to create data contracts in F#] On the road to a really interesting Web Service, I increased the complexity of my "could-not-be-simpler" web service one notch, and added a class-typed argument to the operation. This requires constructing of a Data Contract, so that WCF can build the correct WSDL, and also know ...
For all the power and flexibility that WCF provides, creating a basic web service in C# is easy enough. Essentially, it's just a POCO adorned with some special attributes. Doing the same thing in F#, then, should also be easy enough. I tried this: #light #I @"C:\Program Files\Reference Assemblies\Microsoft\Framew... #r "System.ServiceModel.dll" open System.ServiceModel [<ServiceContract(Config... = "TestWebService", Namespace = "http://coyote-software.com... [<ServiceBehavior(Instan... ...
Many developers are using JavaScript today. However, the programming JavaScript is not pleasant occupation. Therefore, many JavaScript frameworks (jQuery, ExtJS, Prototype, Moo etc) and libraries appeared lately. Today I wish to tell about jLinq library. Its uniqueness consists that with its help we can do LINQ-inquiries in JavaScript a code. jLinq query is looking as follows. var results = jLinq.from(data.users) .startsWith("first", "a") .orEndsWith("y") .orderBy("admin","age") .select(); Thus, ...
Just in case you missed the news, Yahoo has created it’s own query thingy. No, no LINQ provider, it’s a “query language”. Check it out! http://developer.yahoo.com/... Quote: What is YQL? Yahoo! makes a lot of structured data available to developers, primarily through its web services. These services require developers to locate the right URLs and documentation to access and query them which can result in a very fragmented experience. The YQL platform provides a single endpoint service that enables ...
Development related: Persistence ignorance in the Entity Framework discussed with reference to the EFPocoAdapter http://railsenvy.com/ Lots of Ruby and Rails stuff – and some good podcasts and video Scott Hanselman has listed his “must haves” on a machine rebuild. Always illuminating to see other techies “must have” lists EssWork 2.0 is a framework for software development integrated into VSTS. And its free. From Ivor Jacobson - who once cost me a lot of brandy on expenses :-) A video showing construction ...
The next Frederick .NET User Group (FredNUG) meeting will be Wednesday, May 27th at the Urbana Regional Library. We’re pleased to have Jeremy Kadlec returning to FredNUG as well as Steve Andrews who is coming to FredNUG as part of his goal of 52 (yes 52!) talks to the Developer Community this year. It will be an excellent meeting filled with valuable content! The scheduled agenda is: 6:30 PM - 7:00 PM - Intro Topic: SQL Server Dynamic Management Views with Jeremy Kadlec Speaker Bio: Jeremy Kadlec ...
Dynamic query building is most often used in the enterprise world for search screens and other operations. I remember writing code very tediously night and day for a very big search screen. Those days where the nightmares, but good experiences we got. Now these things are made very simple by means of Microsoft's Ado.Net entity framework. ADO.Net Entity Framework is an ORM extension from Microsoft. This is something similar to Linq to Sql . But this one is having some good features and we will be ...
So i finally had some time lastnight to look into LINQ for ASP.NET 3.5. It is simply amazing. I currently build all my applications using ADO.NET, which i think works really well, but at times this approach can be time consuming, building your datatables and your select, insert, update, and delete statements along with your business logic. With LINQ, you simply create your LINQ to SQL class and instantiate a datacontext on the page accessing data, write a few lines to return data from your datacontext, ...
(This posting is a continuation of this blog posting.) If you want to implement this the OOP way, here you have the subclass code (which I'll use myself). using System.Collections.Generic; // Remember to set this to your proper namespace (or use a using statement in // the class with the LINQ projection) namespace MyNamespace { /// <summary> /// Extension methods for the Dictionary generic class. /// </summary> public class ImprovedDictionary<T1,T2... Dictionary<T1,T2> { /// ...
Ever needed to instantiate a Dictionary from a LINQ projection? It is certainly doable, although not extremely straightforward. My first thought was to try and do this: var result = from o in ctx.Orders where o.ID = OrderID select new MyOrderClass { ID = o.ID, Created = o.Created, ExtraData = new Dictionary<string,string... Add("key1", o.Value1). Add("key2", o.Value2") }; If this would work, it would probably be the most clean-looking solution. The only problem with this though is that the ...

A few weeks ago I did a a presentation on LINQ and ADO.NET Entity Framework for the VISUG at Microsoft Belgium. Want the code and presentation ?

Downloads : code and presentation

I've never used a straight-edged razor for shaving, although I've seen one in use and I've played with one and sharpened one to the point that I know I don't WANT to use one (for shaving). I have, indeed, used that thing called a "safety" razor where you screw in a double-sided razor blade into a carriage with a handle. The contraption exposes only enough of the razor to keep you from total exsanguination but still provides a close shave. You can always just unscrew the thing and get directly to ...
LINQ is something that has had my full attention ever since it was released. And I’ve been wanting to do something on this blog with LINQ, but never really found the inspiration to do something “special” with it. Up until now. So it occurred to me that there is not (to my knowledge) anything available that allows you to incorporate your LINQ way-of-work with BizTalk. And why not? There are purposes enough to use LINQ in a BizTalk environment, and it doesn’t even have to be rocket science to get there. ...
Anyone that is working frequently with either LINQ to SQL or the Entity Framework needs to go get a copy of the Huagati DBML/EDMX tools. They plug right into Visual Studio (2008) and allow you to perform many of the tasks that you would think VS would do for you. I just recently had a new dev db get corrupted. I had no backups for it. I also had no scripts generated for it. Argh! What to do? With this tool I was able to reverse engineer my EDMX file and spit out all the SQL I needed to generate the ...
If you’ve read parts 1, 2 and indeed 3 you’ll know we’ve covered the CRD of CRUD, today we will cover the ‘U’ – updates! Updates are more complex than the other scenario’s we’ve covered so far, but not unmanageable. Also – in fairness this is a very simple update, more complex updates will require more thought (duh!) but this should be a good starting point. Let’s get to it! We’ll start on familiar ground – updating the interface, adding an ‘UpdateCar’ method: [OperationContract] void UpdateCar(Car ...
In should say that the first time I looked lambda and linq, making pivot tables was not the main thing I thought about. After helping a few people including one at the msdn (http://is.gd/oG8q) social site, I realized that I also needed to use the lambda in my own EMR project. The problem was to have the lab data of a patient transformed into a pivot table and some of the data summarized by averaging or counting. I had the data in the table in the following format. PatientID TestNo TestName TestVar ...
Before discussing lets have look at the below two pictures and try to guess what is LINQ to SQL. straight forward..... LINQ to SQL acts between your Application and SQL server. It fetches the data-rows from the database and then creates the objects out of it and simply gives you a way to deal with the objects. It always use to be big deal for a developer to get the data from database and manage those in the business objects. A true headache starts when these objects can be deleted, newly created ...
Today I presented ‘LINQ to SQL compared to LINQ to Entities’, a session for the VISUG at Microsoft Belgium. Attendees asked me how one can see the T-SQL statement that LINQ to SQL or the Entity Framework is generating out of the LINQ Query. For LINQ to SQL : Use the log property of the context to redirect the generated query to the output window of Visual Studio. using (MyLINQToSQLClassesDataContext ctx = new MyLINQToSQLClassesDataConte... { ctx.Log = Console.Out; var q = from c in ctx.Categories ...
Let’s play a game of “What if…”. What if you were a Canadian flying from Toronto to Vancouver. The only piece of luggage you had was a metal case containing $5000.00. When you went through security, the officers noticed that you were carrying a large sum of money with you. Now what is the acceptable response from the security officers? Should they be allowed to question you about the money? How about your job, what you were doing in Toronto, what you’ll be doing in Vancouver? Realize that while carrying ...
Nothing special – just a list of good Visual Basic .NET articles I read over the last month. Enjoy: Visual Basic Lambdas are not quite the same as C# Lambdas. This article explains how to work around the differences. Visual Basic needs a hand with iterators as it has no specific syntax. Useful when you live in a world of LINQ and IEnumerable. This article shows you how to create iterators in VB. Combining XML Literals, WCF and LINQ to create temaplates. Interesting stuff. Add “Ruby like” MethodMissing ...
First of all, thanks to all those brilliant people who made the long arduous journey to the UK (and to all those who just happened to be near by). I know it must have killed you to be so far away for so long. I can only imagine how hard it was for you. All of us that couldn’t go really feel for you and feel your pain. Okay! So, for those of us that couldn’t go, some of these guys really did a tremendous job of twittering what was going on during the conference. They absolutely did not have to do ...
Today I’m going to talk about a feature of C# that has been around since 2.0 (with the introduction of anonymous delegates) but which gets nearly no lip service and, despite the fact that most C# developers have probably used it, they’ve probably used it without thinking about it. This feature is called closure, and it refers to the ability of a nested function to make reference to the surrounding function’s variables. This article will make extensive discussion of how delegates are implemented in ...
If you’ve read parts 1 and 2 you’ll know we’ve covered the CR of CRUD, today we will cover the ‘D’ – deletions. We’ll need to update our interface to actually provide this functionality: [ServiceContract] public interface ICarsService { [OperationContract] Car GetCar(int id); [OperationContract] void SubmitCar(Car car); [OperationContract] void DeleteCar(int id); } I’ve decided to delete the car via the identifier we created initially, though there is nothing to stop us using a ‘Car’ instance. Anyhews, ...
I have added another release to the Grommet Library (an extension to the .NET Micro Framework). This release adds default comparers to OrderBy and ThenBy to allow the use of the orderby C# keyword. The code sample from the previous post can now be simplified with the orderby keyword: var feedsToUpdate = from feed in feedList orderby ((RssFeed)feed).LastUpdate descending, ((RssFeed)feed).Name where ((RssFeed)feed).LastUpdate > new DateTime(2009, 03, 20) select (((RssFeed)feed).Name); Also, this ...
The VISUG (the main .NET Usergroup in Belgium) and Microsoft Belgium are organizing 3 events for .NET developers. These events will cover existing technologies and are free to attend. I’m presenting the sessions on LINQ and data access in .NET 3.5 on April 15 from 02:00 PM till 04:00 PM. This presentation takes place at the Microsoft Offices in Zaventem. A language focused overview of the foundations of LINQ in C#3.0 (50 minutes) In this session the language enhancements in C#3.0 on which LINQ is ...
I’m working on porting an existing forum-based community from SMF to a new .NET-based forum platform that I’m authoring. I’m excited about it; I love SMF, but it doesn’t have what I want and frankly, it’s a scary beast to try to tackle. I’d considered using some kind of bridge between it and my code, but I knew I wanted deep integration of the forums with the new community site, and I wanted the community site in .NET. So I made the decision to write an importer to talk between MySQL and my SQL Server-based ...
If you don’t know what eager loading is, Jump to “What’s eager loading?”. Eager Loading Syntax If you are eager loading Products for example in a typical (Categories 1<->* Products) relation, the standard syntax would like: DbDataContext.Categories.In... What is the problem with that? The “Products” part. The word “Products” is a string. If I rename the Products table to ShopProducts or whatever or even remove it from this data diagram and have it elsewhere, or even something ...
LINQ to XML rocks. I use it pretty much day in day out to read mock up data from XML files for prototyping. Today I needed a way to work with an XML file that was embedded in an assembly as an Embedded Resource. Following are the contents of the file: <Users> <User ID="1" Name="Jim"/> <User ID="1" Name="Jon"/> <User ID="1" Name="jack"/> <User ID="1" Name="Matt"/> </Users> LINQ to XML makes working with this very easy. public static XDocument GetDocument(string ...
Last week I gave this workshop/presentation for the syntrawest ITClub on Data Access with ADO.NET 3.5. You can have get a printout of the slides here. Content of the presentation : LINQ as query language LINQ to SQL LINQ to Entities (=ADO.NET Entity Framework) ENTITY SQL ADO.NET DataServices ASP.NET Dynamic Data More workshops are planned : 26/05/09: Windows Communication Foundation (WCF) - A deep dive on Security 16/06/09: Windows Workflow Foundation (WF) - A deep dive on Workflow Services september/october ...
Development related: Extend IE7 and IE8: Make extending IE7 and IE8 that much easier with a little spicIE :-) With SpicIE you can develop your own event handlers, toolbar buttons, menu entries, toolbars and more. Free software for students: UK secondary school students can get free developer software like Visual Studio, Expressions & XNA Games Studio. Trial Virtual Machines to download: 52 to choose from! Daily 2 hour Live Meetings on TFS: www.almcatalyst.com Windows Azure Sample app – Issue ...
On April 1st, 2009, Microsoft is putting on a free 24 hour virtual event covering developer-related topics. There will be 95 live sessions provided via Live Meeting in the following tracks: *Windows Development and Frameworks *Windows Mobile Development *Office and SharePoint Development *Developer Tools, Languages & Practices *Web Development & User Experience More information on each track can be found here: http://www.msfttechdays.com... Macro Shaw will be presenting ...
Here is an interesting issue I noticed when using the Except extension method. I have list of users from which I want to exclude some users: The list of users is coming from an XML file: <Users> <User id="1" name="Jack"/> <User id="2" name="Jim"/> <User id="3" name="Joe"/> <User id="4" name="James"/> <User id="5" name="Tom"/> <User id="6" name="Matt"/> <User id="7" name="Jon"/> <User id="8" name="Jill"/> </Users> The code goes like this: ...
I just had this error where entity framework was complaining about my object already being referenced by the data context that I originally got the object from. In LINQ to SQL I guess this was just taken care of for me. I would get the object in a using statement so that the data context was cleared when I was through with the context. Then I could do what ever I wanted to with the object after that – to include throwing it back to the database. I came across the fix to this issue here: http://social.msdn.microsof... ...
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; ...
In this Issue: Pete Brown(2), Lee, Jeff Prosise, Andrea Boschin, Terence Tsang, Mike Taulty(2), Chris Hay(2), Chris Koenig, Laurence Moroney, Julien Frelat, Andy Beaulieu(2, 3), Joel Neubeck, Gavin Wignall, Jan Jelinek, and Ruurd Boeke. Shoutouts: Congratulations go out to Andy Beaulieu who reports Physics Helper gets 1st Place at MIX09 Show Off! Dan Wahlin spoke at DevConnections in Orlando and reported DevConnections Orlando Talks on Silverlight and LINQ/Entity Framework Brad Abrams gives a link ...
Two day free training event called XamlFest at the Bloomginton, MN Microsoft offices from Tuesday, April 14th 2009 to Wednesday, April 15th, 2009. This will be a classroom style event led by fellow Microsoft’s very own John Pelak. This event will be going in depth on the XAML markup language and how it is used in both WPF and Silverlight 2.0 applications. We will also go deep on how to use Expression Blend to visually design application interfaces. Here's all the information on the event: Check out ...
To be honest, I haven’t been working on my entry to the Dare to Dream Different Challenge lately. I was distracted by a comment on my blog by Jens Kühner correcting my post where I stated that Linq was not possible without generics. Well, that got me searching, and I could only find proof implementations of Linq without generics, but not a full implementation of Enumerable.cs targeted to the Micro Framework. So I started writing one. Although, it is not complete yet, I thought it was far enough along ...
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; ...
Having been asked 5 times today for recommendations, I figure this post is long overdue: There are several books out there but IMHO these are the two you should purchase. Julia is focused entirely on Entity Framework (all 800+ pages!) and Roger takes a broader look at ADO.NET3.5 but does a great job on Entity Framework. Programming Entity Framework by Julia Lerman (Author) and Professional ADO.NET 3.5 with LINQ and the Entity Framework by Roger Jennings (Author) ...
Today I delivered a session introducing Entity Framework at www.devweek.com. I expanded the session to include a brief overview of the new stuff we should expect (but I don’t guarantee) will ship in .NET Framework 4.0 with Visual Studio 2010. First up, some useful links: Main ADO.NET Entity Framework site including “How To” videos Well written overview article My previous posts on Entity Framework Entity Framework v2 features http://blogs.msdn.com/efdes... ADO.NET team blog including plenty on the ...
Note: I just updated the title for this article, sorry to all of you who were waiting for the TechDays Belgium source code and didn't realize it was here :) I just posted the source code of the demo applications I used in my MIX09 talk "Working across the client continuum". The source code is structured as follows: Read the rest of this entry » ...
Recently I wrote about what actions are necessary, that the LINQ-to-SQL data model could work together with ADO.NET Data Services. I wish to add this information with one important fact. Actually, there is an convention on which ADO.NET Data Services tries to define independently key fields in entity. This convention consists in the following – if the entity is not marked with DataServiceKey attribute, following actions are carried out: Among properties of entity property ID is searching. If it exists, ...
Yes, you were not mistaken, having read title. Now we will look how it is possible to work with data from SQL Compact using ADO.NET Data Services. Important remark. Actually, SQL Compact not absolutely correctly to use together with ADO.NET Data Services. SQL Compact initially is not focused on a mode of the multiuser work and it is intended for other purposes – for use as local storage. Using SQL Compact as storage for ADO.NET Data Services can negatively affect productivity of your web service. ...
As a rule, ADO.NET Data Services works over ADO.NET Entity Framework data model. However, work with real projects (and customers:)) sometimes specifies to us other conditions. Frequently there is no necessity to use Entity Framework. And in this case we start to think of use LINQ-to-SQL as data model. In earlier versions of ADO.NET Data Services it is has been simple – create data model, create web-service and it works! When ADO.NET Data Services released, the situation has been changed – at construction ...
I began using LINQ and when I was just about to give the guys at M$ another two thumbs up; I have to give one instead. LINQ is a wonderful tool that has cut my work time in almost half. However, it falls short when it’s time to do a bulk insert. It took me a little over 7 hours to complete a simple task of manipulating 60,000 records and then inserting them. I also noticed that compared to ADO.Net, my CPU consumption was doubled. Sample Code: QQCli qqcc = new QQCli (ConfigurationManager.Conne... ...
We continue to investigate possibilites of use LINQ to SQL as model of data for ADO.NET Data Services. Today we will talk about possibility of change data. I will remind, that ADO.NET Data Services platform gives us possibility not only to select data through web service, but also to update them using methods POST/PUT/MERGE/DELETE. Within data model it is necessary to implement IQueryable interface (for each entity set) for data selecting, and IUpdatable (for datacontext class) for updating. Let’s ...
Next week (23rd March 2009) I am speaking at DevWeek 2009. DevWeek is a great conference which attracts top notch speakers (plus me – I feel such a fraud whenever I present there!). It is IMHO the best developer focused conference we have in the UK and I can’t wait to get there and soak in the great sessions + catch up with familiar faces + meet plenty of new ones. Be warned. There is a rumour that we are being given some new toys (Flip video cameras) to play with while we are there. However don’t ...