Archive for category Software

Learning Windows Azure

I started to learn how to use the Azure Cloud Service from Microsoft this week. Currently it’s still in Tech Preview stage. Unfortunately you can tell that from the SDK documentation.

Here’s some useful links to get you going:

  1. Screencasts: http://msdn.microsoft.com/en-us/azure/dd439432.aspx
    These are quite basic, but trust me, you need them to be basic to get you started.
  2. SDK: http://www.microsoft.com/downloads/details.aspx?FamilyID=80e3eabf-0507-4560-aeb6-d31e9a70a0a6&displaylang=en
    Contains CHTM-style documentation, tools and samples. Don’t expect too much from the docs; they explain enough to get you confused, and then have an API reference. You need to unzip the samples and get into them to start understanding how everything fits together.
  3. Visual Studio Templates: http://www.microsoft.com/downloads/details.aspx?FamilyID=8e90b639-1ef0-4e21-bb73-fc22662911bc&displaylang=en
    This gives you a set of project and item templates which you can use to create and publish Azure applications. Don’t worry about the extra projects it adds to a solution, or the config files. You will learn more about them later.
  4. The Azure developer center on MSDN: http://msdn.microsoft.com/en-us/azure/default.aspx

Assuming you already registered for Azure, that’s all you really need to get started.

The biggest problem I found at first was deploying an app. Once you have generated an Azure project in Visual Studio, you expect to be able to publish it from Visual Studio too. Unfortunately you can’t, and it takes a little more effort. I’ll write more about that in another post.

I also needed help trying to understand what to focus on to get started. So here’s a big tip: Ignore .Net Services, Live Services, and SQL Data Services. They aren’t part of Azure per se. You can come back to them later. First you just need a hosted project and some storage – either blob storage or table storage. (There’s also queue storage, but I bet no one will want to use that straight away – it’s for tying two apps together, which no one will want to do at first.)

I recommend you download the SDK and the Visual Studio templates, create yourself a “Web Role” project (which is really the equivalent of an ASP.Net project), and work on that. Then move onto table and blob storage. You can use the screencasts to help you.

Good luck getting started!

No Comments

Easy Data-loading with LINQ-to-SQL and LINQ-to-XML

.Net 3.5 had some nice tricks in it. LINQ-to-XML was one of them. With the new "X"-types, you can make working with XML really easy.

VB.Net 9 takes it one step further, and lets you write XML in your code without strings.

"Hey Rich, that’s old news," I hear you say. "And who’s interested in VB today anyway?"

Well, apparently there are a lot of VB-er’s still out there. I am mainly a C# developer myself, but I found that VB was perfect for a problem I had recently -  loading of XML data into a SQL Server table.

Read the rest of this entry »

, , , , ,

2 Comments

Design Guidelines for LINQ

Have you wondered if and when you should use the new LINQ features in .Net 3.5?

Like, where should I put a new extension method? Should I use Func<T> or a custom delegate? How do I best implement a mix-in (extension methods on an interface)?

Well, Mircea Trofin has just published a new draft of some LINQ design guidelines. You might just find your answers there.

, ,

No Comments

The LinqDataSource and the Hidden Viewstate

Yesterday I thought I’d learn about the LinqDataSource in ASP.Net 3.5, and got an interesting surprise.

The new LinqDataSource can also be used with a LINQ-to-SQL model to perform updates. You simply add the DataSource to your page, set the table name, and set EnableUpdate to true. Then, using a standard DataControl, you can make updates to your data entities.

The question is, how does this work? It appears to be a bit magical. Read the rest of this entry »

, , ,

2 Comments

How to Update Data with LINQ-to-SQL

When learning LINQ-to-SQL, it’s not immediately obvious how to do an update. Querying is easy, and there are methods for inserting and deleting. Updating usually occurs by modifying an object already known to the DataContext and then calling SubmitChanges on the context.

var product = (from p in dataContext.Products
               where p.ProductID == 1
               select p).Single();

product.Name = "Richard's product";

dataContext.SubmitChanges();

It’s nice to see that MSDN documentation actually addresses the obvious arising question:

Q. Can I update table data without first querying the database?

A. Although LINQ to SQL does not have set-based update commands, you can use either of the following techniques to update without first querying:

  • Use ExecuteCommand to send SQL code.
  • Create a new instance of the object and initialize all the current values (fields) that affect the update. Then attach the object to the DataContext by using Attach and modify the field you want to change.

Read the rest of this entry »

,

33 Comments

Writing Custom Exception Classes the Quick Way

Until recently I thought this was a well-known feature. After demonstrating it a few times, I found out it wasn’t.

A long time ago, in an cubicle far, far away, someone created the .Net Framework. To cut a long story short, they simultaneously produced guidelines for creating Exception classes, which you should always use or face having your fingernails pulled out with a staple-gun.

The guidelines state:

“Use the common constructors shown in the following code example when creating exception classes. “

[C#]

public class XxxException : ApplicationException
{
public XxxException() {… }
public XxxException(string message) {… }
public XxxException(string message, Exception inner) {… }
public XxxException(SerializationInfo info, StreamingContext context) {…}
}

Read the rest of this entry »

, , ,

2 Comments

How to Use Grouping in C# LINQ Syntax

When you started using LINQ, did you think it looked like SQL? I did.

The more I learned LINQ, the more I realized it wasn’t anything like SQL. Take grouping, for example. Because LINQ has a group by statement, and it looks like SQL, I assumed that the syntax for grouping in LINQ would be just like SQL. Ha ha! Wrong! As soon as I tried to use it, I discovered that the LINQ syntax is not only nothing like the SQL equivalent, but the whole grouping concept in LINQ is completely different too.

At first glance, the two syntaxes look slightly similar.

SQL:

select ReportsTo, count(LastName) as NameCount
from Employees
group by ReportsTo

LINQ (C#):

from employee in Employees
group employee by employee.ReportsTo

Ignoring the omission of the select statement from LINQ, and the requirement of a range variable, they do look similar. But looks can be deceiving.

Let me explain why.

Read the rest of this entry »

, ,

11 Comments

LINQ to DataSets – the Missing Manual

Last week I had to prepare a small presentation for a new LINQ workshop. For my research, I browsed through the MSDN documentation on LINQ where I came across a reference to "LINQ to DataSets". I couldn’t find any more information about it though, and so LINQ to DataSets got a small mention in my presentation, but I couldn’t say anything more about it.

This morning I discovered that Fabrice Marguerie and his co-authors have published a bonus 47-page chapter of their book "LINQ in Action", all about this very subject. The chapter is called "Working with LINQ and DataSets", and they have made a PDF version available online for FREE download from the Manning Press website.

You can go get it right now.

Thanks Fabrice, for filling in the missing gap.

I’m going back to update my presentation…

, ,

3 Comments

My own ASP.Net MVP Framework

So, I did it! I finally did it!

I wanted to publish my ideas for a framework, and I did. You can find it on CodePlex at http://www.codeplex.com/aspnetmvp.

Go have a look. I really want to know what you think.

Read the rest of this entry »

, ,

6 Comments

ASP.Net MVC Corollary – What to do?

Dude! I got quoted! And by none other than Rob Conery of SubSonic fame.

It seems like my last post caused quite an unexpected stir. Thanks to both Rob and Scott for taking the time to answer me. I really appreciate it.
Read the rest of this entry »

, , ,

No Comments