by
jwooley via
ThinqLinq
on
7/12/2009 9:20:00 PM
While translating this site over to MVC, I ran into a challenge when converting the RSS feed implementation. Currently I'm using XML Literals to generate the RSS and I could certainly continue to use that track from the Controller similar to the Sitemap implementation on Mikesdotnetting . However, putting the XML generation in the controller directly conflicts with the separation of concerns that MVC embraces. If I were only displaying one RSS feed, I might be willing to break this here. Howev ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
7/10/2009 12:40:00 PM
At CodeStock, I attended Rod Paddock's intro to JQuery session since I hadn't played with JQuery yet. As often happens when I go to conferences, being in the different environment starts to get the mind thinking in different ways. Sometimes the benefit of the conference isn't necessarily something stated directly, but rather a thought when the mind wanders. One such thought occurred during Rod's presentation where I thought that it might be interesting to "query" sets of text over a larger do ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
6/24/2009 3:39:00 PM
With SQL Server, you can use the For Xml clause (read more in BOL ). The quickest option is to add For XML Auto at the end of a SQL statement. You can do this with dynamic SQL or inside a stored proc. If you use a stored proc, the DBML tool doesn't recognize this as XML (and return it as an XElement as it does for XML Data type columns). Regardless of whether you are using stored procs or dynamic SQL, the server returns the result as an array of strings broken up into 4000 character chunks. ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
6/20/2009 7:06:00 PM
As we already announced , the samples for chapters 1-8 of our LINQ in Action book are available through LINQPad . This includes the LINQ to Objects and LINQ to SQL. I've been working on the LINQ to XML chapters (9-11) and hope that we will add them to the download soon. In the process, I've needed to learn a bit about how LINQPad works under the covers in order to add specialized classes. By default, LINQPad offers three options: Expressions, Statements and Programs. With the Expressions, y ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
5/28/2009 12:05:00 PM
When I added the Pingbacks and Trackbacks, I changed the implementation of the Comments to use an inheritance model (TPH) where Comments, Trackbacks, and Pingbacks all inherit from the abstract CommentBase class. To refresh your memory, here's the appropriate part of the DBML designer surface: While this works fine with minimal changes when viewing data, it can cause problems if you are using the LinqDataSource for editing values. When trying to update or delete a record, you may encounter ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
5/27/2009 5:40:00 PM
Recently, I discussed Sending and Receiving TrackBacks on this blog. The TrackBack API is not the only mechanism which blog engines use to communicate between each other about the links that are included in individual posts. Wikipedia lists three methods to keep track of which articles are cross linked: Refback , Trackback , and Pingback . Of these, perhaps the trickiest to implement is the Pingback because it uses the xml-rpc style of communication rather than SOAP or REST that most . ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
5/26/2009 2:56:00 PM
Last week, I announced that my translations of the Entity Framework samples were available in VB . Today the ADO.Net team announced that next set have been posted. These are part of the ADO.Net Entity Framework Documentation Samples . These are the projects that are used in the EF quick start and walkthroughs that come with the .Net documentation. They are a set of mini applications demonstrating using EF within the context of an application. The Course Manager sample was previously trans ... [ read more ]
|
by
jwooley via
ThinqLinq
on
5/26/2009 10:39:00 AM
Yesterday, I showed how we can receive trackbacks from other sites using the TrackBack API . Today, we'll look at the other side of this picture: sending TrackBacks to other sites based on links in the post. Sending a TrackBack entails several steps: Parsing the post to find links to other sites. Checking the target site to see if it supports TrackBacks. Formatting and sending the TrackBack to the target's service. Checking for error responses. Thus with every post I create now, ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
5/25/2009 6:43:00 PM
If you've been following along, I've been working on enhancing this site a bit recently. A couple of the most recent enhancements can be found in the following posts: Paging with AJAX WCF and LINQ Adding Gravatar support to comments Continuing in this tradition, I wanted to include the ability to be notified when other sites post links to my posts. There are several such API's that support this kind of notification, including Trackbacks and Pingbacks. In this post, we'll look at re ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
5/21/2009 4:32:00 PM
For those Visual Basic users out that that have struggled with the fact that the samples were only available in C#, you can now rejoice. There are a number of projects that have now been translated into Visual Basic for your learning pleasure. You can find these samples on the MSDN Code Gallery’s Entity Framework page. At this point the following projects have been translated. Entity Framework Query Samples Compatible with .NET Framework 3.5 SP1 and Visual Studio 2008 SP1 (Visual Ba ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
5/12/2009 6:05:00 PM
These days, it seems that every web site needs to have some use of gratuitous AJAX in order to stay on the bleeding edge. Since we didn't have any here yet, I thought I would throw some in for good measure. I liked the lazy loading of records instead of paging found on some sites, including the Google RSS reader and thought I would see what it would take to add something like that here. If you're not familiar with this paging option, instead of loading a new page of records each time the u ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
5/7/2009 3:15:00 PM
Having a bit more free time than expected, I thought I would take a bit of time and add some features to this site based on some things I've seen at other sites. A quick one is adding Gravatar support to the comments. If you're not familiar with gravatar's, www.Gravatar.com describes them as a g lobally r ecognized avatar , is quite simply an image that follows you from site to site appearing beside your name when you do things. To get a Gravatar, go to Gravatar.com and let them know y ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
2/1/2009 12:51:00 PM
Yesterday, I had the pleasure of demonstrating Delegates, Lambdas and Expressions at the Alabama Code Camp. This is not the first time I presented this. The original demo project is still available in the Downloads section of this site. This time however, I was able to round off the VB set of the demos to demonstrate all of the abilities available in C# 3.0 due to the new Statement and Multi-line Lambda language enhancements coming in VB 10. The complete VB 10 version of the project ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
1/21/2009 9:48:00 AM
When we were writing LINQ in Action, we weren't able to specify all of the possible methods and functions that have supported query translations for a couple reasons.
There were too many to be included in the scope of the book.
The book was being written at the same time that LINQ was evolving and more comprehensions were being supported, thus giving us a moving target that we couldn't ensure the accuracy of when the product shipped.
We realized that over time, translations for m ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
1/3/2009 3:32:00 PM
A couple months ago I added a feature to this site to build a Site Map for this site dynamically based on the information from the database for posts and files for the downloads. If your not familiar with how Sitemap files can help your site searchability, Google has a good documentation about Sitemaps in their Webmaster tools. The SiteMap Protocal is a rather simple XML document consisting of a set of url nodes that consist of the following: loc - URL for the page link lastmod - D ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
10/21/2008 6:19:00 PM
It's been a while since I posted some serious content for which I apologize. I started this site a year and a half ago as a proof of concept around LINQ. When the site went live, I included the download version of the site from the presentations I've been doing on LINQ and Asp.Net. In all this time, I've made significant updates to the site, but haven't made them available, until now. If you're interested, you can download the updated bits from the file downloads here and play with them. I di ... [ read more ]
|
by
jwooley via
ThinqLinq
on
10/21/2008 2:09:00 PM
There are times where you wish you didn't have to worry about legacy code. This is particularly true with programming languages where constructs need to be supported even if they have long outlived their usefullness. Consider the following code that many of us "old-timers" learned to make the TRS-80 in the computer store go into an infinate loop (because the sales person didn't know how to break out of the loop).
Public Shared Sub Main() 10: Dim x As ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
10/20/2008 8:46:00 AM
A couple months ago, I was convinced to try Twitter. In the process, I found www.TweetBeep.com which sends me notifications whenever someone tweets the word LINQ. Today I saw the following:
"my visual studio crashed on retrieving 39,450 records via Linq.. what a shame.. looking for a workaround and a reason.." (name withheld to protect the guilty).
In some ways, this falls into the category of, "Just because you can doesn't mean you should." In this case, the fault lies in the bu ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
10/3/2008 11:07:00 AM
Back at DevLinq (er DevLink ), I had a chance to sit out on the back porch with Keith and Woody and chat about some of the cool features and rusty washers that you can find in LINQ. Head on over to DeepFriedBytes.com and check out our conversation. You can also download the webcast to listen to on demand. Even better, you can listen on your Zune . As always, let me know what you Thinq.
|
|
by
jwooley via
ThinqLinq
on
9/18/2008 4:17:00 PM
A while back, I showed you how to use an XML Mapping file to enable POCO support with LINQ to SQL instead of requiring you to clutter your class libraries with LINQ to SQL attributes. It turns out, the schema for the XML Mapping files ( xmlns =" http://schemas.microsoft.com/linqtosql/mapping/2007 " ) may not be included in your install of Visual Studio 2008. It was missing from mine. Luckily, the file is available on MSDN. If you add it to the schemas recognized by Visual Studio, you wil ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
8/24/2008 7:44:00 PM
In LINQ in Action, we discuss how to add the LINQ to SQL Query visualizer into the Visual Studio 2008 environment. This tool allows you to open a window during debug time to view the TSQL that is generated from the LINQ expression tree. It also allows you to run the query and view the results. If you're not familiar with it, check out this post by Scott Guthrie.
In addition to the query visualizer, you can also build and install the Expression Tree visualizer, not only as a separate applicati ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
8/21/2008 8:10:00 AM
When we wrote LINQ in Action, we took a bit of time to explain how the identity tracking system worked with LINQ to SQL to make sure that changed objects were retained when subsequent queries are requested from a data context. In a nutshell, when you issue a query, the data context translates the LINQ query into TSQL and sends that to the database. The database returns the rowsets to LINQ to SQL. The provider checks the returned rows against those that it is already tracking from previous fetch ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
8/19/2008 10:48:00 PM
There are subtle differences between VB and C# in terms of nullability. This caused a significant difference in the TSQL generated on even simple LINQ queries. Consider the following query from Northwind's Orders table where the Freight column is generated as a Nullable(Of Integer) type:
Dim filtered = _ From o In dc.Orders Where o.Freight > 100 Select o
First ... [ read more ]
|
by
jwooley via
ThinqLinq
on
8/19/2008 10:40:00 PM
The VS 2008 SP1 includes lots of new features (more than a typical service pack, but that's another matter). There are a number of smaller enhancements that could easily go un-noticed otherwise. One of these is to fix a bug in the way the VB compiler generates anonymous types.
In most cases, you will only notice this if you are binding an anonymous projection to a DataGridView or the ASP GridView. With these controls, you will find that the columns used to be generated alphabetically rather ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
7/25/2008 9:49:00 AM
One of the key things that LINQ to SQL does for us is offers a quick way to fill a set of objects with data from a database. Typically this is done by setting up some mapping and calling the GetTable method on the DataContext. There are cases, particularly when you already have an infrastructure set-up to populate objects using a DbDataReader, where it would be nice if you could just populate the columns without the need to set-up a mapping.
The DataContext has a little known method called Tr ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
6/23/2008 8:14:00 AM
You can consume stored procs rather than the standard dynamic sql for accessing child objects. To do this, set up your fetch stored procs and make sure that they return the correct data type (not the standard custom generated type for stored procedures). To load a child collection, create a method on the partial implementation of your context. Name the function "LoadCs" where "C" is the name of the child property accessor from the parent object in the designer. This function will take a type a ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
6/12/2008 1:13:00 PM
At TechEd Developers 2008 in Orlando, I had the pleasure of competing in Speaker Idol. In that competition, we had the opportunity to present a topic in 5 minutes. Unfortunately, the topic I choose really needed 10 minutes to cover at the level of detail it needed. Instead of limiting the topic, I decided to go ahead and present it a bit too fast.
If you want to see the video, or see how to use VB 9's XML Literals and LINQ to XML to fetch data from a web page (that must be XHtml compilant), ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
5/16/2008 10:19:00 AM
Many people have noticed when binding an anonymous type to a grid in VB that the order of the properties does not reflect the order that they were specified in the projection (Select) clause. Instead, they appear alphabetized. Consider the following query:
Dim query = From c In Customers _ Select c.LastName, c.FirstName, c.BirthDate
If you bind this query to a DataGrid or ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
5/8/2008 6:25:00 PM
On page 216 of LINQ in Action , I made a comment that unmapped properties in a mapped class cannot be used in a LINQ to SQL projection. This was true with the beta bits, but only partially true with the release bits. To begin, let's consider the Author table we have in the book samples.
The Author class has separate fields for the first and last name. Each of these is mapped to the corresponding fields in the Author table. In the book, we show how you can create a read only property in a ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
3/18/2008 12:48:00 AM
LINQ makes working with data in its various guises easier. By intergating it into the language, we have rich integrated support for working with data. However, there are times where the syntax is slighly different from what you would typically expect with TSQL. Once case where this occurs is when trying to join two data sources that are related by more than one field (also know as a composite key). This differs from standard joins where one table has a primary key and the other table has a fore ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
2/22/2008 5:46:00 PM
I was working to come up with some creative uses of LINQ to XML for my new talk I'm giving at the Huntsville, AL Code Camp . I figured it would be good to include a sample which queries a large XML document. Remembering that the complete works of Shakespeare were available in XML form, I did a quick search and found a version at http://metalab.unc.edu/bosak/xml/eg/shaks200.zip . This file separates each play out into separate XML files. Since I wanted to find out which parts had the most line ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
2/18/2008 8:41:00 PM
Using a single self referencing table is a common database pattern for trees of data. As an example of this concept, we can use the Employee table in Northwind. It has a self referential relationship set up using the ReportsTo field. If we drag this into the LINQ to SQL designer, it will infer the self relation and create the appropriate EntitySet/EntityRef relationship exposing it with the Employees (for subordinates of a given employee) and Employee (for the reference to the boss). ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
2/10/2008 3:28:00 PM
So, you're thinqing about convering existing code to use LINQ? Here are a couple quick tricks to get you started:
1) Have your regression tests ready. No warrantee is implied as to your success once completing the following.
2) Find any imports to System.Data.SqlClient including global imports and remove them. See what breaks in your application and re-write it using LINQ to SQL instead of ADO.
3) Search for iteration loops (For Each/foreach) or explicit calls to enumerator.MoveNext  ... [ read more ]
|
by
jwooley via
ThinqLinq
on
2/10/2008 2:47:00 PM
In case anyone is interested, I have put together a sample port of the original Personal Web Starter Kit using LINQ rather than the standard ADO data tier in the PhotoManager.vb class. With this version, we can eliminate all of the stored procedures and rely on LINQ for our entire data access. In this implementation, I intentionally attempted to retain the original method signatures where possible to make migration more seamless. The project site is at http://code.msdn.microsoft ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
1/20/2008 9:09:00 PM
Last time , we added categories to the web view of the ThinqLinq site. This time, we're going to add them to the RSS feed. Because RSS is "Really Simple", adding the categories is fairly easy. According to the RSS specification , <category> is an optional sub-element of <item>. It can additionally contain the domain that contains that category. In our case, we will point the domain to our implementation that displays all posts for a given category by passing the category id to the ... [ read more ]
|
by
jwooley via
ThinqLinq
on
1/20/2008 8:38:00 PM
Ok, so I've been a bit busy this weekend adding some nice stuff for this site. One thing that I wanted to add was another RSS feed, this time for the file upload section. If you want to subscribe to the File RSS feed, direct your aggregator to the following link: http://www.thinqlinq.com/FileRss.aspx .
Of course, since this is a learning site, I'll let you in on the code needed to accomplish the task. As you may guess, LINQ makes serving up XML from an object collection using a heterogeneous ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
1/10/2008 10:16:00 PM
When I first released ThinqLinq, the only filtering I applied was to only select the top 20 posts. I was recently asked if I could extend the implementation so that it the aggregation feed could be filtered based on the categories. Since ThinqLinq uses LINQ for the data interaction, it is relatively easy to add filtering to the existing query.
However, in this case, the filtering is not a simple Where clause on the underlying table. That is because the table structure uses a Many t ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
1/9/2008 8:41:00 PM
In the LINQ in Action forum , a user asked about returning multiple result sets from a single stored procedure. Below is one way of dealing with this issue.
In the procedure, we used multiple results rather than a result with a return value (through RETURN or an OUTPUT parameter). Here we need to use the IMultipleResult rather than the default ISingleResult implementation. It appears that the designer does not map IMultipleResult in the final build, so we are going to nee ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
10/24/2007 12:00:00 AM
Today, I'm not looking at sending mass spam using LINQ to pull a list of recipients. I'm actually referring to the ability to generate the message body using XML Literals. Using the System.Net.Mail.MailMessage object, we can easily send emails to an SMTP server.
The body of the email can either be plain text or HTML. Dynamically generating the text is often a laborious task involving a string builder and lots of method calls. The body corresponds to the body portion of a HTML page. If you us ... [ read more ]
|
|
by
jwooley via
ThinqLinq
on
10/9/2007 12:00:00 AM
In my VB 9 language enhancements talks, I do them withalmost all coding on the fly as I find people often can comprehend the code. I start by building a quick class that is used throughout the demos. To assist, I do use the snippet functionality in VB. For example, if you type "property" and then tab twice, the designer will generate a private field with public property accessors. The if you change the highlighted values, any associated names will be changed as well.
Private newPropertyV ... [ read more ]
|
|