.NET Answers

ASP.NET, HTML, CSS, Visual Studio, CSharp, VB.NET and other programming items of interest.
Subscribe
  • Home
  • About Me
  • Advertising
  • Click Here to Ask a question
    • Privacy Policy
  • Site Map

Multi-layer LINQ via Extension Points

February 06, 2008 By: Dave

As promised a few days ago, I will be covering multi-layered architecture as it relates to LINQ.

The first thing we need to evaluate is how Microsoft intended multi-layered architecture to work.  I mean, if we want to know how to do this, the best place to start is with the people who created the technology in the first place, right?

So, remember when we discussed partial functions?  Partial functions are the key to understanding the multi-layer capabilities of LINQ.

The LINQ to SQL classes are composed of the DataContext class and the class that represents a row in each table.  We’ll call that the Table class for now.  Each of these classes have a set of partial functions.  The DataContext class has the following partial functions:

  • partial void OnCreated();
  • partial void InsertTable(Table instance);
  • partial void UpdateTable(Table instance);
  • partial void DeleteTable(Table instance);

where Table represents a table class.  You would, therefore have an Insert, Update and Delete partial method for each table in your DataContext.

The table classes also have a set of partial methods defined for them.

  • partial void OnLoaded();
  • partial void OnValidate(System.Data.Linq.ChangeAction action);
  • partial void OnCreated();
  • partial void OnFieldChanging(typeName value);
    partial void OnFieldChanged();

So you can write code that will fire when the row is created, loaded, or validated as well as when the field is being set, or right after each field has been set.  Just to avoid any confusion, loaded gets called right after the row is filled from the database and validated is called right before it gets saved back.

So, here’s what you might be able to achieve with this.

  • Create special Insert, Update and Delete handlers for tables that need special handling.  For example, maybe you can’t implement cascading delete at the database level for whatever reason, you could handle it in code during the delete event.
  • Do data transformation on rows when they are loaded and transform back when the row is saved.
  • Validate data as you are changing the record.

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Related Post

  • Is LINQ Multi Layered?
  • Partial Classes and Partial Methods
  • Using The LINQDataSource
Bookmark to:

Add to Del.icio.us Add to digg Add to DotNetKicks Add to DZone Add to Facebook Add to Slashdot Add to Stumble Upon Add to Technorati
Hide Sites
Tags: 3-tier, asp.net, linq, multi-layer, multi-tier, visual studio

Comments are closed.

← Partial Classes and Partial Methods
10,000 GDI Objects Ought to be. . . →
  • Search

  • Subscribe

    U COMMENT
    I FOLLOW

    Subscribe in a reader

    OR

    Subscribe via e-mail

    Enter your email address: 

    Delivered by FeedBurner

     

  • Follow Me

    • Twitter
    • FaceBook
    • Digg
    • StumbleUpon
    • Propeller
    • Delicious
    • Plaxo

     

  • Recent Posts

    • ASUS Eee PC 1005HA-PU1X-BK Black Netbook
    • jQuery – Date Picker
    • Using VB.NET From CSharp
    • iTextSharp – Adding Images
    • Hungarian Notation – Use What Works, Spit Out The Bones
    • Pre Order Windows 7
    • jQuery Dialog – With Validation Controls
    • iTextSharp – The easy way
    • Structure of my ASP.NET Web Applications
    • 35% Off Accronis True Image 2009 Home
    • VB.NET Hide Module Name
    • ASP.NET/VB.NET – Video Training
    • Does jQuery Make Us Lazy?
    • PDFs Using iTextSharp
    • Programming SEO – Ping



  • Advertise on this site through Lake Quincy Media
  • DotNetNuke Sponsor

     

    Most Valuable Blogger
  • Sponsor

  • Categories

    • Advanced CSharp
    • Advanced VB.NET
    • ASP.NET MVC
    • Did you know
    • DotNetNuke – Module Development
    • DotNetNuke – Skinning
    • internationalization
    • iTextSharp
    • jQuery
    • none
    • Seach Engine Optimization
    • Silverlight
    • SQL For Programmers
    • Twitter
    • winforms
  • Cloud

    .net ajax architecture asp.net book books containers csharp css dal dataset datasets dotnetnuke events gridview images internationalization internet explorer javascript jQuery json linq listview modules ms-sql MVC objectdatasource programming reflection seo Silverlight skinning sql testing tsql tutorial Twitter twitterizer vb.net video view Vista visual studio webservice WordPress
  • Archives

    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
    • January 2008
    • December 2007
    • November 2007
    • October 2007
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
    • Privacy Policy
  • Calendar

    February 2008
    S M T W T F S
    « Jan   Mar »
     12
    3456789
    10111213141516
    17181920212223
    242526272829  
  • Blogroll

    • Alvin Ashcraft’s Morning Dew
    • ASP.NET Consulting
    • Life Hacker
    • Remember Anything
    • The Price of Their Toys
    • Uncategorized Thought


.NET Answers © 2007 - 2008 All Rights Reserved.
Entries and Comments.