Hilton Giesenow's Jumbled Mind

the madness that is...

News

This is my little spot in cyberspace where you will find a collection of random (but mostly software-related) thoughts and ideas that are frightening in their shining brilliance (or something like that ;->).
 
Please enjoy your stay and feel free to Contact Me.
 
Microsoft MVP

.Net Links

BlogRoll

Misc. Links

Syndication

Browse by Tags

All Tags » Linq (RSS)
Validation Method Timing in LINQ To SQL
The LINQ To SQL designer-generated classes contain 3 different ways to implement validation based on property values. Two of these are internal, in the form of partial methods, and one is external in the form events on the domain classes themselves. However, the timing around these differs slightly, so I'm going to examine them according to the timing. To look into these approaches, I'm using the Customers table from Northwind. I've got it on my LINQ To SQL designer, and I've implemented...
Posted: Aug 07 2008, 09:47 PM by hiltong | with 2 comment(s)
Filed under: ,
Generating Enums From Database Tables
I posted earlier about how to use enums in LINQ To SQL , and I spoke about why I think enums are useful. The only problem with this approach was that you had to create the enums by hand, even if you had the same data sitting in a lookup table. If you were at my recent Code Generation with T4 Chalk 'n Talk at Tech Ed South Africa, you would have seen me generate enums automatically from the database, which is what we're going to do below. Note: If you're not familiar at all with T4, check...
Using Enums With LINQ To SQL
I don't know about you, but I'm quite a fan of using Enumerations (Enums) in my apps. I'm all for more readable, more explicit code because I think it helps a lot with maintainability, and enums help with that. I'd much rather read a line of code that says: customer.CustomerType = CustomerType .Good; than customer.CustomerType = 1; Of course, it means you also get Intellisense when you're writing the code. Another advantage is that enums, which are usually lookup types and very...
Posted: Aug 06 2008, 02:40 PM by hiltong | with 3 comment(s)
Filed under: ,
Displaying LINQ To SQL's Actual SQL Queries in your ASP.NET Page
I've made use of the Log property on the DataContext class in a few of my LINQ To SQL posts . Usually, it's been in a console application, and we're just looking at the SQL output in the console window, so we use: dataContext.Log = Console .Out; However, in a web application, this won't help. If you want to see the output of your SQL directly in the page, you can use: System.IO. StreamWriter httpResponseStreamWriter = new StreamWriter ( HttpContext .Current.Response.OutputStream);...
Posted: Jul 16 2008, 10:54 AM by hiltong | with 1 comment(s)
Filed under: ,
Using User Defined Functions (UDFs) With LINQ To SQL (And In LINQ To SQL Where Clauses)
User Defined Functions, or UDFs, provide method-like functionality with TSQL statements. If you've not used them before, you can read more here . In this post I'm going to assume you've got some basic knowledge of UDFs and show how to use them in LINQ To SQL. First up, you can go and create a simple UDFs. I'm using the tools in Visual Studio to create my UDF but of course you can use Management Studio. My very simple UDF appears as follows: CREATE FUNCTION dbo.SimpleLookup ( @SomeInt...
Posted: May 21 2008, 02:56 PM by hiltong | with 3 comment(s)
Filed under: ,
LINQ To SQL : Dynamically Adding a Shared OrderBy Clause
One of the features of LINQ queries is Deferred Execution, which Charlie Calvert discusses here with some great examples . This feature can be used to let you create a shared function to handling adding specific functionality to all queries for a specific type. For instance, if we have a simple Northwind DataContext like the following: then, if we want to write a simple query like the following to find all customers who live in cities starting with an 'L' (or perhaps a less arbitrary query...
Posted: May 12 2008, 04:13 PM by hiltong | with 4 comment(s)
Filed under: ,
Spotted in the Wild: Be Careful With Loading Your Data!
I've blogged before about how LINQ To SQL actually requires the same careful design and development practices as other OR/M frameworks (see for instance my post on LINQ To SQL performance ). Part of this involves being aware of when and how calls to the database are executed, and with this is mind I found an interesting sample in the DinnerNow .net 3.5 reference sample application: public bool UpdateOrderStatus(DinnerNow.Business.Data.RestaurantOrder restaurantOrder, string status, Guid WorkflowId...
Posted: Apr 03 2008, 09:41 PM by hiltong | with no comments
Filed under: ,
LINQ To ...
I mentioned in a post a little while ago about the various LINQ To projects I had seen, but Charlie Calvert has a much more complete list up here . It includes the following LINQ Providers: LINQ to Amazon LINQ to Active Directory LINQ to Bindable Sources (SyncLINQ) LINQ over C# project LINQ to CRM LINQ To Geo - Language Integrated Query for Geospatial Data LINQ to Excel LINQ to Expressions (MetaLinq) LINQ Extender (Toolkit for building LINQ Providers) LINQ to Flickr LINQ to Google LINQ to Indexes...
Posted: Mar 19 2008, 07:05 AM by hiltong | with no comments
Filed under: ,
Avoiding a Base Page In ASP.Net
I blogged a while ago about how I'm not comfortable with using a base class that all of your pages inherit from in ASP.Net. In .net 1.x this was really the only way to enforce behaviour and share functionality but it meant all of the developers on the team had to remember to do it, and it was a manual task. There are ways around this, like overriding the default templates in Visual Studio . Of course, you can still choose to use a base page class in ASP.Net 3.5, one that inherits from System...
More LINQ Links
A few days ago I put up a list of Getting Started with LINQ To SQL Links . Chris Rock (not the comedian) has another good list up as well . Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted: Feb 24 2008, 08:08 AM by hiltong | with 3 comment(s)
Filed under:
Getting Started With LINQ To SQL
Considering I've put a few posts up about LINQ To SQL, I realised I've never shared some of the initial links I passed to other team members as well. If you're looking into using this technology, here are some worthwhile links to follow. Some are tutorials, some are tools, some are just worthwhile pieces to understand with this new technology. Also, some are more general LINQ-related than LINQ To SQL specifically. Essential Reading http://weblogs.asp.net/scottgu/archive/2007/09/07/linq...
Posted: Feb 20 2008, 04:03 PM by hiltong | with 2 comment(s)
Filed under: ,
Lazy Loading in LINQ: LoadWith And AssociateWith DataLoadOptions - Part 2 - AssociateWith And Tying Both Together
In a recent post, I discussed using the LoadWith method on the DataLoadOptions in LINQ To SQL. This method allows you to explicitly specify which objects must be automatically retrieved from the database and it can make an important difference to the performance of your LINQ To SQL application. Recall that the usage of LoadWith was something like this: using ( NorthwindDataContext dc = new NorthwindDataContext ()) { dc.Log = Console .Out; System.Data.Linq. DataLoadOptions dl = new System.Data.Linq...
Posted: Feb 12 2008, 03:43 PM by hiltong | with 4 comment(s)
Filed under:
Lazy Loading in LINQ: LoadWith And AssociateWith DataLoadOptions - Part 1 - LoadWith
When using an OR/M like LINQ To SQL, it is vitally important in almost all instances to understand the conception of lazy loading - what it means, what it does, and how to best work with it. In short, Lazy Loading is the concept of the data only being retrieved from the database when you want to use it. For instance, you can load the customers you want, work with them, e.g.: var customers = from c in dc.Customers select c; Console .WriteLine(customers.First().CompanyName); and then, when you want...
Posted: Feb 12 2008, 02:27 PM by hiltong | with 4 comment(s)
Filed under:
LINQ Performance - In Memory Collection
Steve Herbert has an interesting performance evaluation discussion up on his blog (this is raw LINQ, by the way, not LINQ to SQL). Initially, he has 3 samples, the first 2 using LINQ and the 3rd without. These are the results: Item#1 – averaged 2643 ms Item#2 – averaged 671 ms Item#3 – averaged <1 ms However, make sure to read through the comments on the post. What emerges is from Eric Lee who comments: "So the lesson to learn here is that when you use Linq, you either need to make sure your...
Posted: Feb 12 2008, 11:26 AM by hiltong | with 2 comment(s)
Filed under:
Keeping Control of Your Extension Methods
Visual Studio Magazine has a nice list of some tips for keeping control of your Extension Methods so that they don't get out of control. [Via Kathleen Dollard's Ask Kathleen column ] Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted: Feb 06 2008, 05:18 AM by hiltong | with no comments
Filed under:
More Posts Next page »