Fluent NHibernate: How to Create Bidirectional Many-to-Many Relationships with Additional Attributes on Relationship Table
Suppose you have a relationship that looks like this in your database:
This is a common use-case. In this instance, I wanted to be able to create a table which would log all of the times an individual user read a particular item from an RSS feed. I used an identity key here instead of a composite key so I could take advantage of NHibernate’s auto-magical SaveOrUpdate feature.
Normally with a ManyToMany relationship between two entities in Fluent NHibernate you would simply define a HasManyToMany attribute on either side of the entity, and .Inverse one of them such that only one entity is actually responsible for persisting changes to the database.
In this type of relationship, where your many-to-many relationship actually has additional...
Just a quick post for any readers in the Southern California area who are interested in learning more about Windows Azure. My team is putting on an event at Microsoft's Los Angeles offices on Thursday morning from 9:00am to 1:00pm and its intent is to help introduce Azure to any curious developers who've never had a chance to play around with it before. These guys are all top-notch Azure experts and will be able to answer your questions better than I ever could :p
Register or learn more:
ASP.NET MVC3 has been a major boon to my productivity as a web developer since I started using it at the beginning of November – the new Razor view engine has been attracting most of the attention with this iteration of MVC, but one extremely sexy feature has gone unnoticed thus far: Remote validation.
Remote validation was one of the new features added in the November Release Candidate (RC) for MVC3 – I had a chance to demo it in front of the LA .NET User Group last night and it was a monster hit.
You’ve all seen remote validation before – ever see one of these when you’re signing up for a service like Twitter?
That’s remote validation at work. Twitter, Facebook et al make...
This is a quick post, but for anybody who isn’t using Expression Blend (which automatically puts all of the Windows Phone 7 icons for you in a drop-down list as default resource values for images) and wants to get access to icons in Windows Phone 7, here is where you can find them:
C:/Program Files (x86)/Microsoft SDKs/Windows Phone/v7.0/Icons/
Putting this online for the benefit of the .NET LA User Group – this content is meant to accompany my talk on ASP.NET MVC3:
ASP.NET MVC3 links:
- ASP.NET MVC3 Installer
- ASP.NET MVC3 RC Whitepaper
- ASP.NET MVC Roadmap
- Getting Started with NuGet (Package Manager for Visual Studio)
PeerLearningSite on Github (Example Project with ASP.NET MVC3 RC)
- Razor Syntax Example (List)
- Razor Syntax Example II (Create)
- Razor Syntax Example III (Details)
- Remote validation:
- Data annotations:
- Valid Email Address Attribute (custom Data Annotation)
- DI with Ninject
James Gregory is one of my heroes in the .NET community – he’s the creator of Fluent NHibernate, my favorite new ORM (Object-Relational Mapper) for my ASP.NET MVC projects. James expressed some dismay earlier today when a newbie Fluent NHibernate developer posted a $100+ bounty for a few basic usage examples; having just recently taught myself the very things the developer was asking for, I can empathize.
NHibernate (Fluent NHibernate runs on top of it) is a bear of an open source project for new developers – it’s a mature project that solves a problem with a massive surface area and the NHibernate community is comprised of experienced developers who’ve been using it for years. It can be difficult for new developers to get involved, as the learning curve is steep even for just adopting the project, let alone contributing to it.
So how can we...
I gave a talk at Code Camp Los Angeles a couple of weekends ago on how to consume REST APIs in .NET – the emphasis was really on understanding RESTful principles and on the OAuth workflows + implementing them in Windows Phone 7.
It was meant to be a 100-200 level introduction to the REST in .NET – if you’ve implemented OAuth before in .NET then this is old news for you :p
I’ve been leaning heavily on Laurent Bugnion’s MVVM Light Toolkit framework in the course of learning Windows Phone 7[footnote:If you're interested in developing for Windows Phone 7, you can download all of the development tools for free from http://developer.windowsphone.com/] development for my work as a developer evangelist at Microsoft. It’s a fantastic framework and it does an excellent job of enabling SOC in Windows Phone 7 application development.
However, during some of my experimentation with the framework I’ve run into some initially puzzling development pitfalls that I wanted to share and demystify.
These pitfalls might also apply to vanilla Silverlight and WPF in general, but my experience has been with Windows Phone 7 development so I’ll qualify these pitfalls accordingly:
I wrote this example in conjunction with the lightning talk I gave at SHDH #40 on MVVM for Noobs, and I thought that developers who are new to developing in Silverlight or for Windows Phone 7 might benefit from it.
One of the major issues I had in moving from ASP.NET MVC to MVVM in Windows Phone 7 was learning how to let go and let Silverlight do a lot of the heavy lifting for me, particularly in the area of data binding and managing the life cycles of your business objects.
Please take a look at the attached source – I’ll be writing up a follow-up post with some specific learnings in the near future.
I'm at Microsoft's Silicon Valley Campus this weekend where we're hosting SuperHappyDevHouse #40 - I'm going to be giving a lightning talk on MVVM for Noobs in the next hour or so and I wanted to post my presentation online as I think some of you might find it to be of some use. My presentation is largely focused on the MVVM Light Toolkit for Windows Phone 7, and I really struggled to grasp MVVM when I first started developing for WP7 largely because of some long-held views I brought over from ASP.NET MVC and tried to force upon Silverlight and MVVM.
This presentation should help shed some light on how to get some of the...