Thursday, August 14, 2008

Returning multiple record sets from Oracle

When you need to retrieve complex data shapes from a database, you traditionally have been restricted to either dealing with multiple (and possibly sparse) rows per entity, or else performing multiple calls to the database and iterating the results to create your object graph.

The former CAN be pretty performant, but is a pain to implement the graph generation state-machine.

The latter suffers from the latency involved in setting up multiple database calls.

What’s needed is the ability to retrieve multiple data sets, but with just ONE database call.

SQL Server trumpets this as a feature, but Oracle’s been able to do this for a while as well. The problem has been that it’s very badly documented how you access the data through ODP.Net. Now I’ll show you how.

Let’s start by creating a stored proc that returns some data from 3 independent tables:

 

    PROCEDURE PRO_GET_MULTIPLE
    (
     p_first OUT SYS_REFCURSOR,
     p_second OUT SYS_REFCURSOR,
     p_third OUT SYS_REFCURSOR
    ) IS
    BEGIN
         OPEN p_ first FOR
              select * from table_one;
         OPEN p_ second FOR
              select * from table_two;

         OPEN p_ third FOR
              select * from table_three;
    END;

 

Easy enough PL./SQL there. Let’s now retrieve the data using ODP.Net:

 

            OracleDatabase db = OracleDatabaseFactory.CreateDatabase ();

 

            OracleCommand cmd = new OracleCommand("MY_PACKAGE.PRO_GET_MULTIPLE", connection);

            cmd.CommandType = CommandType.StoredProcedure;

 

            OracleParameter staffTypeResult = new OracleParameter();

            staffTypeResult.ParameterName = "p_first";

            staffTypeResult.OracleDbType = OracleDbType.RefCursor;

            staffTypeResult.Direction = ParameterDirection.Output;

 

            OracleParameter nameTypeResult = new OracleParameter();

            nameTypeResult.ParameterName = "p_second";

            nameTypeResult.OracleDbType = OracleDbType.RefCursor;

            nameTypeResult.Direction = ParameterDirection.Output;

 

            OracleParameter identifierTypeResult = new OracleParameter();

            identifierTypeResult.ParameterName = "p_third";

            identifierTypeResult.OracleDbType = OracleDbType.RefCursor;

            identifierTypeResult.Direction = ParameterDirection.Output;

 

            cmd.Parameters.Add(staffTypeResult);

            cmd.Parameters.Add(nameTypeResult);

            cmd.Parameters.Add(identifierTypeResult);

 

            //Return the filled Dataset

            DataSet dataset = db.ExecuteDataSet(cmd);

 

Note how we add output parameters for each of the tables the stored procedure returns? This is where the magic lies – the OracleDatabase object knows how to fill a dataset from multiple out-parameters via the ExecuteDataSet command.

Now I should point out that the OracleDatabase type is our customised Enterprise Library Data Access Block provider, so your mileage may vary with other EntLib Oracle providers.

Once you’ve got a DataSet, of course, you can iterate it in the usual manner:

 

            DataTable table = dataset.Tables[tableIndex];

 

            int index = 0;

            foreach (DataRow row in table.Rows)

            {

                Console.Write(string.Format("{0} : {1} {2} {3}",

                    index, row[0], row[1], row[2]));

                Console.WriteLine();

                index++;

            }

 

And that’s all there is too it!

 

Wednesday, August 13, 2008

Yield and prepare to be enumerated!

Raymond Chen has written an illuminating blog post on what *actually* happens when you write an iterator in C#.

This explains clearly what’s going on – essential for getting your head around how to use them, and in particular the yield return and yield break statements.

Start Leeks linked to it as part of his series covering yield.

Syntactic sugar: http://blogs.msdn.com/oldnewthing/archive/2008/08/12/8849519.aspx

Update: Raymond has a posted two follow-up articles.

Top Tip: Don't mix and match in webfarms

Tom details a problem on the ASP.Net Debugging blog about web farms running ASP.Net apps.

Turns out that ViewState is NOT compatible across versions of ASP.Net, or even processor architectures.

Read about it here: http://blogs.msdn.com/tom/archive/2008/08/13/system-indexoutofrangeexception-on-a-webfarm.aspx

 

Tuesday, August 12, 2008

Free ASP.Net and Winforms components

Joe Stagner links to a set of 60 free ASP.Net and Winforms controls now available from DevExpress.

Find them here:  http://www.devexpress.com/Products/Free/WebRegistration60/

Busy day for Microsoft...

It’s clearly a busy day for Microsoft today – just looking at the sheer volume of postings on the MSDN blogs should tell you that something’s up. But what?

Well, today is a major release day for the developer devision:

·         Visual Studio 2008 Service Pack  and the NET Framework 3.5 Service Pack 1 have both been released - good article by Somasegar here.

·         ADO.Net Data Services (formerly known as “Project Astoria” was released today too – see the Project Astoria Team Blog.

·         And finally, the Entity Framework has RTM’d as well. Their Team Blog has plenty of info.

Oh and don’t forget that SQL Server 2008 was released a few days ago as well.

Good times!

 

Thursday, August 07, 2008

Microsoft Sync Framework - RELEASED!

I spotted this on Eric Nelson’s blog first (thanks to his twitter feed) – the Microsoft Sync Framework has finally been released!

Why is this good – well, it SHOULD make things much easier when building occasionally connected applications. Now I just need to work out how to connect it to Oracle via my business services layer. Exciting stuff.

Read all about it: http://blogs.msdn.com/ericnel/archive/2008/08/07/microsoft-sync-framework-released.aspx

Get the goods: http://www.microsoft.com/downloads/details.aspx?FamilyId=C88BA2D1-CEF3-4149-B301-9B056E7FB1E6&displaylang=en

 

Tuesday, August 05, 2008

We're hiring!

We’re looking to hire a .Net developer to work on our next-generation product using the latest Microsoft technologies. Here’s the skinny – and if you’re interested, say you heard about the role from here!


Position

.Net Developer reporting to the Development Manager, based in Altrincham, Cheshire.

Candidate Profile

The development department has a flat structure with small teams formed according to the needs of the developments in question. This means that we do not have fixed team leader roles but allocate responsibility based on experience and skills. An ideal candidate must:

  • Be a self motivator with the drive and enthusiasm to take on new challenges
  • Be flexible and adaptable (but disciplined) when approaching tasks
  • Work well within teams and be able to foster good working relationships
  • Be prepared to take total responsibility for the completion of tasks
  • Be a good communicator, (both written and oral) and be confident making presentations on technical subjects to co-workers
  • Be technical rather than man-management oriented

The candidate must have a minimum of 1-2 years demonstrable experience in a commercial environment developing AJAX style ASP.NET web applications in C#. Experience with Silverlight 2.0 and WPF would be a significant advantage.

Role

To work in a team of analyst/programmers, developing and maintaining the in4tek’s next generation software products including work on customer specific portals, web services, integration projects and web applications using leading edge technologies form Microsoft and Oracle.

Approximately 80% of the time will be spent designing and developing new modules, with the remainder allocated to maintaining and enhancing existing software.

Specific activities within the role include:

  • Assisting with the production and review of User Stories and Functional Specifications
  • Working from Functional Specifications to formulate software designs and create Design Specifications
  • Working from Design Specifications to design and develop coded modules
  • Developing and executing Unit Tests to validate code.
  • Analysing and correcting software deficiencies and coding faults
  • Peer review of specifications, designs and code.

Personal development with the aim of obtaining Microsoft Certification will be encouraged.

Skills/Experience

KEY: R = required, D = desirable

Skill/Experience

Degree level qualification in IT or Business related subject

R

At least 1-2 years commercial .Net experience in C#

R

Demonstrable experience of ASP.Net 2.0/3.5 with AJAX

R

Experience of structured methodologies for software design and UML.

D

Experience of Agile methodologies of Software development

D

Experience of developing within a n-tier architecture

D

Experience of the design of n-tier architectures

D

Commercial Oracle and PL/SQL development experience (or equivalent SQL Server)

D

Database design experience (structure, relationships and triggers)

D

Experience of working to ISO9000 / TickIT standards

D

Knowledge of XML and its use in specifying and implementing software interfaces

D

Experience of Silverlight 2.0 and WPF

D

30 Essential PDF Documents

Rob Caron links to an excellent entry on the positivespace Graphic Design blog that gives “30 (actually more) Essential PDF Documents Every Designer Should Download”.

That’s bedtime reading sorted: http://www.positivespaceblog.com/archives/pdf-documents-designer/

How often do you check in?

Eugene Zakhareyev has an interesting commentary today on how often developers check their code into source control, and the control gates that some organisations can use to ensure quality of the checked in code.

Read it now or else: http://teamfoundation.blogspot.com/2008/08/check-in-your-stuff-now-or-else.html

 

Monday, August 04, 2008

Fun with dragging panels (a.k.a. Silverlight goodness)

Martin Grayson has started blogging about the silverlight controls that the MS CUI team developed for the Patient Journey Demonstrator.

This is really good news, because it gives us an insight into how some of the most compelling UI in the market has been developed (and a leg-up on doing it ourselves).

Silverlight goodness here: http://blogs.msdn.com/mgrayson/archive/2008/08/01/silverlight-2-samples-dragging-docking-expanding-panels-part-1.aspx

 

 

Friday, August 01, 2008

Thursday, July 31, 2008

Mike Taulty's been playing with Silverlight... Again.

More goodness from Mike Taulty - connecting Silverlight 2 (beta) to ASMX services.

Why is this important? Because it gives us a VERY quick and easy way of providing data to Silverlight from its hosting website.

One to remember for the (near) future.

Read about it: http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/07/31/10659.aspx

The definition of "Done"...

Raymond Lewallen has posted an interesting piece on the definition of "Done" (aka complete, finished, good-enough-lets-just-ship-the-thing-and-worry-about-bugs-later) in terms of Agile and Lean methodologies, and in terms of the value "Done" brings to a company.

One point I agree with wholeheartedly is this:

As the people who write software, we might not always be aware of the value a product provides to its company, thus we might not understand why certain feature sets are created before others and it might not make sense to us. 

Definitely worth reading:  http://codebetter.com/blogs/raymond.lewallen/archive/2008/07/31/getting-done-the-lean-way.aspx

FW: Using client templates, part 1

Bertrand Le Roy has posted the first in a series of articles on the AJAX client templating features in the upcoming ASP.Net 4.0 release.

This will make things SO much easier for those cases where we want to get performance improvements over using UpdatePanels, but DON'T want to have to inject the markup from Javascript code.

Templating goodness here: http://weblogs.asp.net/bleroy/archive/2008/07/30/using-client-templates-part-1.aspx.

Onions and Architecture

We've been trying to do it all along, just not knowing it (or doing it right!)

Yesterday, Jeffery Palermo posted his second article on "Onion Architecture" - makes a LOT of sense when your application becomes not just a webapp, but an enterprise solution.

Interesting…

http://jeffreypalermo.com/blog/the-onion-architecture-part-1/

http://jeffreypalermo.com/blog/the-onion-architecture-part-2/

Discuss, compare, contrast - enjoy

Passwords - add salt to sage advice

Recently I've been spamming colleagues with nuggets, that should have been on here, so I'm going to start cross-posting from now on.

And with no further waffle, here's today's first nugget:

Karl Seguin has posted a neat little article on password strength - no rocket science here, but it's one of those things that's well worth re-stating to remind us as developers that we should always strive to meet or exceet best practice. And it's amazing the sites that DON'T require strong passwords.

A worthwhile read: http://codebetter.com/blogs/karlseguin/archive/2008/07/30/password-you-re-doing-it-wrong.aspx

Thursday, January 10, 2008

knom's developer corner : Behind the Scenes of LINQ - Part 2

In his latest post on the internals of LINQ, knom finally gives a tutorial explanation of Lambda expressions and how to use them...

Either that or I was just two dumb to get it before!

Read and enjoy: knom's developer corner : Behind the Scenes of LINQ - Part 2

Friday, August 24, 2007

Mix:UK 07

Not really .Net related, but I have to admit to excitement at the prospect of going to Mix:UK 07 down in London in September.

Interestingly, the social networking aspect is already hotting up, with a Backnetwork set up and a Facebook event starting to draw in the attendees. Will I go as far as to import those attendee contact lists into my PDA to take? Well, knowing my inability to remember and match names to faces, it'd probably be a good thing to do.

Technically, I'm really going to be interested in the Silverlight tracks - right now I'm almost desparate for the Silverlight team to implement the basic forms controls (buttons, text boxes, etc). Whilst better control support is planned, it does seem to be a very large omission from the 1.1Alpha release.

Of course, there have already been some community projects to rectify that deficiency, as well as commercial offerings, but how compatible would these be with Microsoft's own library, and how much effort would it be to back-migrate from a 3rd part library after the fact?

Anyway, roll on Mix and I'll see you in London!