Browse by Tags
All Tags »
Linq (
RSS)
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...
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...
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...
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);...
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...
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...
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...
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...
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...
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!
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...
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...
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...
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...
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!
More Posts
Next page »