I only used VB's dynamic language features in the sample because the sample transparently switches between LINQ, web services or straight DTOs. I didn't want messy code to deal with three types with the same shape but different types.
In a "normal" app you'd almost certainly just pick one of those techniques. The result is that you'd have one set of types and so you can just use strong-typing directly against those types. For example, the business assembly can reference the LINQ DAL assembly and just use the LINQ DTO types.
For update/insert/delete operations, I recommend having the DAL implement methods that accept strongly typed parameters for those operations. This is what the DAAB does, and what you'll get with LINQ to SQL automatically. Many other DAL tools work that same way.
You can get an idea of what I'm talking about by looking at the Data Access region of the new Resources class
http://www.lhotka.net/cslacvs/viewvc.cgi/trunk/ProjectTrackervb/ProjectTracker.Library/Resource.vb
I know it is VB, sorry, I'm still porting the new property declaration code to C# before I can convert ProjectTracker... But you can see how the LINQ DTOs are used in DP_Fetch/Insert/Update/Delete. All that comes from a totally separate project (ProjectTracker.DalLinq) that is only deployed on the app server.
No, there's no elegant way to do dynamic calls in C#. It is reflection or nothing. You can wrap the reflection in an elegant API I suppose (and you'd want to, because to get it right like VB or Ruby or whatever requires a lot of code - a lot of type checking, dealing with edge conditions, type coercion, etc).
PTrackerDataContext and SecurityDataContext are created by the LINQ to SQL (L2S) support in Visual Studio 2008. In fact the entire ProjectTracker.DalLinq assembly was created using drag-and-drop in VS 2008 - I did no coding or modifications to anything there.
This also means I didn't create the DTOs. They were created automatically as part of the dbml file. Their naming is entirely as decided by Visual Studio, I just did drag-and-drop.
My original intent was to see how far I could get before needing to do manual work around LINQ. But in the end I was pretty happy with the default code and did no extra work!
The only issue I encountered was the L2S code doesn't like stored procedures that return multiple result sets (like getProject and getResource). I was unable to use those two stored procedures, and had to do direct LINQ statements in Project and Resource. Not a big deal, but it took me a while to understand why I wasn't getting the right child data from my queries when I was using the sprocs.
Yes, it is absolutely possible for L2S to handle multiple result
sets. But not if you use the VS designer to create your L2S entities.
When I built the ProjectTracker stuff I consciously chose to use
the VS designer, because I expected that’s what most people would want to
do.
As it turns out (not to my surprise), L2S is now effectively
obsolete so it doesn’t really matter a lot. Though personally I prefer
L2S at the moment, but I’m sure EF 2.0 will be much more usable than 1.0.
Rocky
From: alef
[mailto:cslanet@lhotka.net]
Sent: Friday, November 07, 2008 7:07 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Deep Data pattern - Inserts/Updates
For the multiple results I've found the following article
(LINQ to SQL: returning multiple result sets):
http://blogs.msdn.com/swiss_dpe_team/archive/2008/02/04/linq-to-sql-returning-multiple-result-sets.aspx
So it is possible to reuse the SP's getProject and getResource.
Copyright (c) Marimer LLC