RSS

LINQ to SQL only goes so far.

05 May

I have just finished re-writing my ailing photography website. I have taken the opportunity to write it afresh using ASP.Net MVC and LINQ to SQL. Whilst the latter is hugely more sensible than programming against a database it did highlight a flaw quite early on.

‘Entities’ in LINQ to SQL (i.e. database tables / views) are connected to each other via Associations. These map 1-1 with the Relationships in your database. Unfortunately, you can’t customise these objects thus denying the developer and means to filter entities. Example:
I have 2 main entities in my application: Albums and Photos. An Album can contain many Photos and a Photo must be part of one, and only one, Album. I then added an IsExcluded property to the Photo entity. Unfortunately, I can’t set the Association between the 2 to recognise this filter.
Solution 1: Create a new View called ‘IncludedPhotos’ and use that in the domain model.
Solution 2: Move to LINQ to Entities.
Advertisements
 
Leave a comment

Posted by on May 5, 2009 in C#

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: