Syndicate

News

My name's Marco De Sanctis and I'm an IT professional from Italy. This is my technical blog, about .NET and related application development and design technologies.

Download my Resume (.doc)

Recent Comments

10/23/2008 at 3:48 PM

sorry, my previous post was not complete... I trie...
by glondi

Read more...

9/22/2008 at 10:03 AM

Good one!!!Could you please post source code for t...
by Nisa

Read more...

9/10/2008 at 5:53 PM

I didn't even realize people were aware of the WPF...
by Mike Brown

Read more...

9/8/2008 at 1:22 AM

Marco,How are you handling scenarios where you nee...
by ctodd

Read more...

9/3/2008 at 1:00 AM

@ctodd: Hi,basically for the reasons I described a...
by Marco De Sanctis

Read more...

Recent Posts

Crunch mode is a pure waste of time, energy and money

7/31/2008 at 5:41 PM

Read more...

Double Click on the .sln file doesn't open Visual Studio on Vista

7/27/2008 at 9:02 AM

Read more...

Domain Model & Aggregates: when do master-detail associations happen?

7/22/2008 at 4:08 PM

Read more...

How I Got Started in Software Development

7/14/2008 at 12:16 AM

Read more...

Unleash the power of VisualStateManager with custom states

6/30/2008 at 12:12 AM

Read more...

Crunch mode, overtimes, weekends spent at the office, are at the very first sight the easiest way to maximize production to meet strict deadlines: my experience is that actually many companies operating in the Italian IT market intensively use this approach. Is the effort worth the gains? Is a tired employee able to work at the same quality level of a fresh one? Obviously not, crunch mode reveals to be counterproductive after a short amount of time. Francesco Carucci, a member of the Italian .NET User Group, recently posted a link to a very interesting article every PM should read.

Here it is, enjoy.

Technorati Tags: ,,

It's a very annoying bug I had to cohabit with for a while. Today I was less patient than usual and I decided to get rid of it :-)

I googled for a minute to find a comment on this post with the solution I needed:

It works when you set both Launcher (C:\Program Files\Common Files\Microsoft Shared\MSEnv\VSLauncher.exe) and IDE (C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe) to run as administrator. (Right click .exe and select Properties -> Compatibility, and choose Run as Administrator)

Oh... obviously a solution could be to directly bind the .sln files to devenv.exe, but I think this is a nicer one.

kick it on DotNetKicks.com

Technorati Tags: ,

During my experience as a consultant, I usually come across domain models in which entities are so interconnected that my head begins to hurt just a minute after I'm trying to figure out where each aggregation symbol leads to, and often the source of all pain is the overuse of master-detail relationship.

An association in a domain model is something etheral, something that apart from its implementation, represent a logical connection between two or more abstract entities. It usually translates itself as a reference in a Object Oriented world and, for example, as a FK relationship between two tables in a relational database.

Now, let's consider a Bill - BillDetail relationship: no one would disagree if I modeled it with the following couple of classes, building a two ways master-detail association:

image

When we project it to a relational database schema, it becomes something like this:

image

Relational representation lacks a lot of the expressivity the object oriented paradigm provides: looking at the classes topology, we can explicitely see that one Bill instance holds a reference to a collection of BillDetails, and thanks to BillDetail.ParentBill property, we can walk that association in both directions while navigating the object graph; all those infos are only implicitely stored in the relational FK association.

In fact, what happens when we consider the Customer the bill belongs to? Let's start from DB schema this time, as most of us are (incorrectly) still used to do while designing a domain model:

image

Now, the inexperienced (but somehow smart) designer should feel that something's different between the two aforementioned examples, even though the relational representation is exactly the same: the association from a bill towards its customer is something we all agree with, but what about the mirrored association? Should we blindly equip our Customer entity with a Bills collection? Or should we simply ignore that side, perhaps providing a GetBillsByCustomer(..) service if we really need to walk from a customer to his bills?

There's a subtle differerence going on between these two examples, something that, once again, is not easy to infer if we're using the database schema as the starting point for our modeling process. A bill detail is something unuseful if taken away from its root; the "Bill" entity with all its details, encompasses the business concept of a real world "Bill". Using a DDD term, they are an Aggregate, whose root is the Bill itself. In that case, implementing a master detail relationship between the two makes a lot of sense, because you're always going to access each bill detail coming from the main Bill entity (you should never access directly each bill detail, according to what Eric Evans states in its Domain Driven Design book).

The relationship between Customer and its Bills now is clearly different! There's nothing bad on directly referencing a Bill, without coming from the Customer, actually a Bill makes a lot of sense (and has a huge business meaning) even though we don't even take care of which customer it belongs to! in other words, Customer and its Bills are not an aggregate.

Why we should avoid master-detail relationship between the two? Because associations are cool, but don't come for free: they have a great cost in terms of complexity and performance, even though we can leverage some ORM to limit the impact on the application. What could be the purpose of a "Bills" property into the Customer class? Even if we suppose to lazy load it, simply accessing it would trigger a query for every bill he has, regardless of the period, of its paying status, and so on. Does it have a business meaning? I don't think so, but that wrong design choice makes us paying its cost anyway.

In other words, a good rule of thumb is: if it's not an aggregate, limit the cohesion and try to avoid master-detail relationships because they are expensive.

I hope many of you agree with that.

kick it on DotNetKicks.com

A couple (perhaps more?) days ago, my friend Simone tagged me with the brand new meme How did you got started in software development? Uhm... ok... here we go ;-)

How old were you when you started programming?

I can't tell it for sure, it must have been when I was 6 or 7 with my father's Pc IBM (who was actually doing it professionally). Anyway... I'm talking about early 80s here.

How did you get started in programming?

My father wanted me to learn how to do it, although I was very young and all that I could do was summing two numbers or playing some notes on the internal beeper. After that very early period, I focused more on videogames for some years, until Visual Basic 1.0 came out. I was so excited that I decided this would have been my life's profession.

What was your first language?

Basic

What was the first real program you wrote?

It was a car taxes calculator I made for a company that hired me during summertime (I was still a student). I made it in Visual Basic for MS-DOS (can anyone remember it?)

What languages have you used since you started programming?

So many... C, C++, Assembler, Basic, Visual Basic, C#, HTML, Javascript, Java... Oh... and VHDL too, as I've been working on digital controlled power supply too.

What was your first professional programming gig?

As I said before, I joined a company to do some work during summer time while I was still a student. Then I re-joined the same company many years later, after my degree in engineering.

If you knew then what you know now, would you have started programming?

Uhm... I think so... I'm actually so happy on what I do every day. However, if I could, I would take some different path on my professional career.

If there is one thing you learned along the way that you would tell new developers, what would it be? 

Try to work with the best, and someday you'll become one of them too.

What's the most fun you've ever had ... programming?

Too easy... having diner with my friends at UGIdotNet after a meeting!!

Who do I tag?

Uhm... what about my friend Alkampfer? :D

Property triggers are the WPF feature I miss the most in Silverlight 2: I really liked writing behaviors in declarative style with XAML and Styles and it was somehow frustrating being forced to use C# code and event handling to achieve similar results in Silverlight.

Although it's not here for exactly the same puropose, VisualStateManager is a great improvement to fill the gap thanks to:

  • Blend visual support
  • automatic state transition animation

Those two features, combined with the opportunity to inject custom states at your own will, make VisualStateManager so poweful that you're going to miss it once back to WPF, at least until it won't be supported for smart clients too.

Let's suppose I want to animate a textbox to change its background color when mouse pointer overs it. If I was in WPF I would have attached a trigger to the IsMouseOver property, in Silverlight we got no triggers, but we have Blend and VisualStateManager.

So what I do is putting a TextBox in my UserControl and ask Blend to customize its template:

image

As we can see, we got no states for the standard TextBox so VisualStateManager seems to be unuseful at first: should we once againf rely on procedural code to achieve our goal? Not at all (or, more exactly, almost not at all). Even though standard TextBox has no built-in states (it doesn't specify any in its attributes nor it invokes any state transition, as, for example, Button does) we can easily add our own simply editing the generated style XAML markup.

What we need is a custom StateGroup, called MouseStates, and a couple of states, Normal and MouseOver, so what we do is opening Visual Studio to have intellisense while typing, adding a reference to System.Windows namespace and writing the following lines of code:

image

Visual Studio complains about using VisualStateManager.VisualStateGroups attached property; however, don't care about it, everything will compile without errors. Ok, now back in blend to continue editing the control template:

image

As you can notice, Blend recognizes the 2 newly added states and suddenly adds them to the States panel. Now, we can animate the TextBox background as we would usually do:

image

Now we only need one last step: adding some code to invoke state transitions when the mouse pointer overs or moves away from the TextBox. So, back in Visual Studio, let's add a couple of event handlers:

image

Now, if you build and run the project, you'll notice how the TextBox gracefully changes its background color from white to shaded red. However, our textbox won't work in another UserControl unless we don't add the same event handling code to it. It would be preferrable to build a custom StateTextBox and internally hiding all that logic. Doing it is extremely easy, as it consists only on creating a class which inherits form Textbox and writing code similar to the previous one:

image

Notice the two attributes I added to the class declaration to describe the control's state machine structure; Blend is supposed to read them to show controls states when editing its template. Unfortunately, (as I wrote some days ago) Blend June CTP current version has template editing capabilities only for controls which belong to System.Windows.dll. It means that even if we use StateTextBox, we'll still need to manually do all the stuff. However, it still has the advantage to leave the page code behind free from any textbox state transition code.

As usual, source code is available here.

kick it on DotNetKicks.com

I've been recently doing some experiments on Silverlight and the new Blend June CTP. I'm amazed by the design support to custom template editing it provides, although I couldn't get it work with my own custom controls.

I though I was mistaking something, perhaps forgetting some attribute or whatever else; after 2-3 days of tests, I finally gave up...

Today I've found this post explaning that

Currently Blend doesn't support copy ControlTemplate that are not define in System.Windows.dll. But you should be able to create an empty template and edit it.

Ok... at least it wasn't a fault of mine..

Technorati Tags: ,

TransactionScope constructor has an overload that lets you specify a transaction timeout:

image

The example above sets up a 1 hour timeout on the new transaction. I was using a similar approach to execute an Oracle stored procedure which was doing some batch processing that took about 30 mins. to complete. Anyway, I could se the transaction being rolled back after about 10 minutes, even though the OracleCommand itself had a proper timeout and no exception was raised by the underlying stored procedure.

Pretty strange, isn't it?

After some research, I've discovered that the TransactionManager class, which ultimately manages the transactions lifespan, has a readonly MaximumTimeout property, that can be set only at machine.config level and has a default value of 10 minute:

image

This is the maximum time limit your transaction can last, regardless of what you specify on the aforementioned constructor. In my case, I decided to move it to one hour limit.

Hopes this saves you a little time ;-)

kick it on DotNetKicks.com

As Corrado Cavalli pointed out in his blog (sorry, it's in Italian), in Beta 1 custom controls didn't inherit their parent's default template; that means they didn't have any visual representation unless we explicitely provide a default template for them. It was a bit annoying, especially when we only needed to add some logic to standard controls, like creating a CustomTextBox that accepts only numbers, for example.

I was happy to realize that in Beta2 this limitation has gone: when building custom controls, we no longer have to create a default template for it, as it's inherited from its base class (if none is provided). Starting from Corrado's example, let's create a CustomButton class

image

Now, if we place it in a Silverlight user control:

image

we obtain exactly what we expected:

image

Fair enough!

If you are excited about Silverlight 2 as I am, and you can't wait for its upcoming beta realease, you'll surely enjoy this: Silverlight 2 Beta 2 SDK Documentation is available.

Let's hope it anticipates the SDK public download only for a few hours.

kick it on DotNetKicks.com

Technorati Tags:

I was going to reply to a feedback to my last post, but from how much I was writing I realized it could deserve a post on its own.

When we decide to adopt the Domain Model pattern to represent data, we're going to deal with complex object graphs: it means that instead of SomeRelatedEntityId properties, we will have concrete references to related entities, a property of SomeRelatedEntity type in this case

Obviously, when you start a business transaction and you know from the beginning that the property X will be accessed, it could be (not always, read below!) a wise choice to eager fetch it to avoid too many DB round trips. However, I consider LazyLoad very useful in at least two practical cases:

  • n-level Master-Details: for example, a form with a header to edit the master entity, a grid below for its details and a button for each row which opens an AJAX modal popup to edit the detail's details. Without LazyLoad you should execute a huge query on the beginning (or many smaller ones) to fetch everything, and perhaps the user only wants to modify a Master's field. Oh... and what if the 2nd level details have many-to-one associations towards other entities? How big should our join be?
  • There are good chances that the related entity is still in the identity map: let's think about a list of entities with many-to-one association towards the same entity, for example a list of bills of the same customer. Without lazy load, you would fetch the same data many times, with lazy load and identity map, you will have no joins, only one query towards the Customers table, then the same entity will be used for every Bill.