If you have an object type mapped to table1 and you need a piece of info from a related object type (thats mapped to a table2) then you can use a view (rather than a table) to make this attribute available in object type1. However this can cause issues with updates. So instead of a view you can use a computed column within object type 1 to gather the related data from the other table. This computed column uses the formula attribute within the nhibernate XML mapping file for object type 1.
Example
Object of type 1 requires a value from a related object of type 2. in this example the data type is a string and the relationship between the two objects is a one to one (so no issues with non existant records or multiple instances). This relation is actually already mapped but uses lazy loading becuase of the size of type 2 class (we don’t want to load the other type becuase it takes too long). However we still require this one string from the type 2 class in certain circumstances but dont want the performance hit of loading type 2.
We could use a view rather than the table within the NHibernate XML mapping file for type 1 but NHibernate will break if we need to perform an update - even if we are not updating this extra column (we do want to perform an update and we don’t need to update the string but the update = “false” has no effect).
So instead, within the object/table1 mapping file, add a new property to inform NHibernate of this new attribute within object type1. Please note the use of qualifiers within the SQL as NHibernate uses alias’s when it emits SQL to the datastore and that SQL will break if you don’t follow the syntax below exactly.
<property name="Name" type="String" formula="(SELECT <tableName2>.<columnName> FROM <tableName2> WHERE tableName2.<primaryKey> = <foreignKey>)" update="false" insert="false"/>
On Sunday I added the full Microsoft web development stack (ASP.NET v3.5, Silverlight, MS SQL 2005) to the hosting options I can now offer clients.
First client to make use of this new capability was Tiered Solutions Hosting itself - I knocked up the web site and published it in a few hours. It was great to be using VS2008 and all of the lovely ASP.NET features rather than the PHP I’ve been using for the last 8 years.
Mosso - Rackspace cloud hosting. Very sexy.
GoGrid - More cloud hosting.
Brinkster
Free
30 mb web space, 500 MB WEB TRAFFIC (limited to 16.7 mb web traffic per day), Brinkster control panel, ASP 3.0 , ASP.NET
xml 4.0
wap enabled
flash enabled
ssi - server side includes
MDAC 2.8
MS ACCESS
.NET MOBILE INTERNET TOOLKIT
ONLINE FILE MANAGER
Advanced
• 5 Free Domain Names
• 500 GB Web Space
• 6000 GB Web Traffic
• 2000 Email Accounts
• ASP/.NET/PHP
• 250 MB MySQL DB
• 250 MB SQL Server DB
• Website Builder
$28 per month
Pro
• 2 Free Domain Names
• 350 GB Web Space
• 3500 GB Web Traffic
• 500 Email Accounts
• ASP/.NET/PHP
• 250 MB MySQL DB
• MS Access/MySQL
• Website Builder
$10 per month
M6.Net
Both Brinkster and M6 seem to offer ASP.NET + PHP side by side.
I’ve been using Rhino Mocks v3.5 for the last month and it kicks butt! The new AAA notation, the use of mocks without creating the repository and the lamda notation mean that mocking out tests is a helluva a lot faster and much easier to read than previous versions.
I can now say that I wouldn’t want to go back to previous versions of the .NET framework just becuase of this one tool you get with v3.
Rhino Mocks is a mocking and stubbing framework for testing .NET code. I’ve known about it and used it on and off for a couple of years but never gotten into it too deeply for the following reasons:
- The code that gets produced is confusing to a non test/non mocking person. It appeared to be too much effort to learn it’s syntax for what it was offering. I say this from the perspective of other developers in any given team that I might be working with and NOT from my perspective.
Why is the other developers perspective important?
Becuase if I started introducing this kind of code into a project then I’d have to justify it to other team members and they too would need to get up to speed with it. This extra work is not to be taken too lightly.
- It’s only relatively recently that I’ve taken the TDD approach to development and I’ve therefore had no real imperative to expend time/effort in looking into this area more deeply. BTW this is one of the best reasons for choosing to use TDD; it automatically drives you to want to learn about producing better code to help enable better TDD. It actually quantifies what “better” code means, rather than just being a woolly term that no two developers could ever agree on.
So, with this in mind, I’ve actually started to use Rhino Mocks in anger over the last nine months to improve my development efforts.
This includes:
- Using the Stubs to quickly create stubbed versions of underlying sub-systems of functionality. There are many reasons why you might want to do this.
- Using Mocks to help me quickly refactor my code around interfaces rather than concrete implementations.
Conclusion very quick way to stub out some underlying object/system/service. In the past I’d tend to create an actual stubbed object/system/service but with this technique you don’t actually have to do that. You either place the Rhino Mocks into your calling code directly (if it’s only used in one place this is the quickest but rather dirty) or develop an interface to the system your going to stub, stub it and then use Dependency Injection (DI) to allow your calling code to use it.
- Actually doing proper behavior testing rather than my more usual state testing.
InternalsVisibleToAttribute
Just spent the last 30 minutes trying to remember the name of this bloody attribute .. finally found it after much googling and thought it best to record it here so I can find it in the future a little quicker.
InternalsVisibleTo: Testing internal methods in .Net 2.0 - Useful overview.
M$ reference on this system.runtime.compilerservices.internalsvisibletoattribute class
The argument against .. which I currently don’t buy. The alternatives are worse.
M$ reference on the access modifier Internal.
UPDATE
There is an issue with using this attribute and strongly named assemblies. You’ll get an “Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations” error.
Read Read Black Wasps article on C# Friend Assemblies and how to get around this error.
.. and loving it.
I’ve dived straight in and I’m investigating how we need to use a 3rd party charting component to display large amounts of project information in a Gantt stylee within a complex WinForm app.
The 3rd party product (GTP.NET) is not a bad starting point but it has limited control scrolling abilities in one of it’s two dimensions. I’ve created custom code to work around this.
I’m currently ironing out some of the implications of the customisation and also moving onto performance/usability testing.
Great stuff 
I’m rubbish at remembering Linq short cuts and tricks, I keep having to google ‘em. So this time I’m making a note of the one post I keep coming back to: 7 tricks to simplify your programs with LINQ .. cheers Igor 
Debug vs. Release Flavor and Debug Symbols
Due to the optimisation you get with the release version of a project (eg replace a normal method with an inline version) there won’t always be a one to one mapping of source code to the code running within the app domain but it’s better than nothing.
.. yep, managed to crash NUnit.
Or at least get it to throw an exception with one of my tests.
Not sure why yet .. no time to review the details at the moment.