Tuesday, 22 March 2011

LINQ + Stored Procedure Optional Parameters

Whilst fixing a bug today I came across a nuance of LINQ.

One of our internal notification emails was failing to send emails to the relevent box.
Checking the error logs led me to discover it was failing on the CCAddress field.
Now,  this field is optional in the procedure  but, from the looks of it rather than it being null it was being set to "" (empty string).

A while back I had added a method to our Email.cs business object.  Simple enough a method to SendEmail using an existing stored procedure which adds all the data to the relevent  queue table.  I could simply have used LINQ to add another queue item but, to maintain consistency  I chose to simply call the procedure's data access object.

Apparantly  when you create your data access layer  the objects created dont take into account the fact that parameters can be optional.

Eventually thanks to the solution I found here :

I found the solution here:

Basically you have to create an overload for the SP LINQ call.  No problem and easily done but, shouldnt this be create with the data objects automatically?

It's somewhat annoying, I mean this is hardly an unusual circumstance is it?

Friday, 4 March 2011

Arrrgh errata

Now I could of course claim I was testing you but the pure and simple fact is I got it wrong.

Whilst I was declaring
<code>FileInfo TheFile = new FileInfo(logoPath);</code>

I was actually then doing

Instead of

Perhaps this is a lesson to not blog about coding on a Friday afternoon.

Hope it made you chuckle.

System.IO.FileInfo - Delete a file

Just something I stumbled across today.
Why if you are creating an instance of the System.IO.FileInfo class do you then also have to supply the file path if you want to call the Delete method?

FileInfo TheFile = new FileInfo(logoPath);
if (TheFile.Exists)


Now let me quote the class summary for you

Provides instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of System.IO.FileStream objects.

I beg to differ!

Whilst the methods are instance (in the sense they are not declared as static)  but surely having to supply the path when you call Delete is a contradiction.

Curiously though I notice that the Delete method

public override void Delete();

Does not actually specify a parameter.

So where does it come from?
Have I missed something?