I do not think you are in the minority with ADO.Net.
Look what happened to LINQ To SQL since the book came out - MS "killed" it already. Well they stopped working on it anyway. EF is just the next greatest technology from MS.
I plan to stick with "raw" ADO.Net into the future as it should be the underpinnings of whatever MS comes up with next. Besides not every database is designed using relationships etc so some of these technologies can't be leveraged as much as you might want.
I have not made the move to Managed properties yet so I won't try to respond to your other comments.
Joe
sroberts:
As a side issue, I do now worry that I am perhaps in a minority of people using CSLA and ADO.Net with SQL Server and that I must learn LINQ as quickly as I can to stay in step with Rocky's progress or maybe I should be learning about the ADO.NET Entity Framework....
I took a gamble on L2S with the book, and lost. But I really couldn't win. ADO.NET EF wasn't released yet, so I really couldn't use it (and I find version 1 to be iffy anyway). And I personally use raw ADO.NET as a general rule.
But if the book didn't use "current" technology then some people would see the book (and/or CSLA) as irrelevant because it uses "old" technology.
The reality is that the ADO.NET code in ProjectTracker 3.0 is the same for 3.6. The data portal hasn't changed that radically. The only difference is the new Child_XYZ methods. You had to write those before too - but you got to pick the method name. Now the data portal dictates the method name (and reduces the code you have to write), but the ADO.NET parts should be unchanged.
(except that you probably want to use the ConnectionManager class now, as that makes things a lot easier)
I digress, but one of the main lessons I took from the 2005 book is never to depend on Microsoft sticking with any particular data access technology. Our legacy app we are replacing first used ODBC, then DAO was the greatest thing since sliced bread (sorry, I'm dating myself ;), then we went back to ODBC for SQL Server and Oracle. Then Microsoft came out with .NET and essentially orphaned the entire C++ community and also moved to dissimilar data access technologies (e.g. ADO.NET, which really doesn't even have anything resembling a fully scrollable result set).
This is exactly why I went with an ORM (which I'm really just using as ADO.NET SQL generator). It supports some 12 different back-end databases (of which we currently support 4 or so), and CSLA was easy to bolt on top of it. When we can't use it anymore, I can swap it out with something else without having laced the application with some technology that MS decides is now obsolete (although I suppose that can and will eventually happen with C#, etc.).
I really liked that CSLA 2.x was more data layer agnostic, but it is certainly true that the new L2S features built in are a convenience that you can choose to use or not, and you can still use whatever data access method you want. You can (and should IMHO) design your app so that the DAL is swappable and you can replace it with something else down the road without a complete rewrite.
Do you really think v2.x was more data layer agnostic?
Certainly I’ve added some optional helpers to deal with
ADO.NET, LINQ to SQL and ADO.NET EF, but I’ve also added ObjectFactory
which opens up whole new avenues of being DAL agnostic. And all the 2.x
concepts work as always.
Rocky
From: rsbaker0
[mailto:cslanet@lhotka.net]
Sent: Saturday, January 31, 2009 5:49 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Peer review of my DataPortal code required
I digress, but one of the main lessons I took from the 2005 book is
never to depend on Microsoft sticking with any particular data access
technology. Our legacy app we are replacing first used ODBC, then DAO was the
greatest thing since sliced bread (sorry, I'm dating myself ;), then we went
back to ODBC for SQL Server and Oracle. Then Microsoft came out with .NET and
essentially orphaned the entire C++ community and also moved to dissimilar data
access technologies (e.g. ADO.NET, which really doesn't even have anything
resembling a fully scrollable result set).
This is exactly why I went with an ORM (which I'm really just using as
ADO.NET SQL generator). It supports some 12 different back-end databases (of
which we currently support 4 or so), and CSLA was easy to bolt on top of it.
When we can't use it anymore, I can swap it out with something else without
having laced the application with some technology that MS decides is now
obsolete (although I suppose that can and will eventually happen with C#,
etc.).
I really liked that CSLA 2.x was more data layer agnostic, but it is certainly
true that the new L2S features built in are a convenience and you can (and
should IMHO) design your app so that the DAL is still swappable and you can
replace it with something else down the road without a complete rewrite.
There are a couple ways to get/set the property values.
One is to use ReadProperty() and LoadProperty():
LoadProperty(IdProperty, dr.GetInt32(“Id”));
cm.Parameters.AddWithValue(“@id”,
ReadProperty(IdProperty));
If you’d like, you can replace the ReadProperty() values
with the use of BypassPropertyChecks:
using (BypassPropertyChecks)
{
cm.Parameters.AddWithValue(“@id”, Id);
}
And if you always have a set block on your properties (use a
private set block for read-only properties) then you can use
BypassPropertyChecks for loading properties too:
using (BypassPropertyChecks)
{
Id = dr.GetInt32(“Id”);
}
The results are the same regardless, so it is really a matter of
style and what you find simpler. I tend to use BypassPropertyChecks these days –
though I still need to use LoadProperty()/ReadProperty() in some cases, because
I don’t always have accessible property get/set blocks.
Rocky
RockfordLhotka:Do you really think v2.x was more data layer agnostic?
Certainly I’ve added some optional helpers to deal with ADO.NET, LINQ to SQL and ADO.NET EF, but I’ve also added ObjectFactory which opens up whole new avenues of being DAL agnostic. And all the 2.x concepts work as always.
Rocky
Well, maybe this was a slight overstatement, but after our last discussion of transaction management and the CSLA ContextManager, my inital reaction was "Great, maybe I can use that instead of my home-grown solution". Then I went and looked at it, and it turned out (at least to my first read) that it's only useful if your using Linq.
There are several manager classes:
ConnectionManager (for any ADO.NET model)
ContextManager (for L2S)
ObjectContextManager (for ADO.NET EF)
My guess is that you just looked at ContextManager, which is L2S
only.
But ConnectionManager manages a normal ADO.NET connection
object, so any DAL that uses a connection may be able to use it. Certainly if
you create your own ADO.NET based DAL, you could use it within your DAL. Or if
you are using a DAL based on some other technology, the only requirement is
that you be able to pass the connection into the DAL rather than having the DAL
open its own connection.
For example, L2S will automatically open a connection to do a
query. But you can, if you want, give it a pre-opened connection before doing
the query, and it will use that pre-opened connection. Most Microsoft data access
technologies work that way, because they want to leave the flexibility for you
to open and manipulate the connection, and still use that connection for
working with things like L2S or EF or a TableAdapter.
Rocky
sroberts:...With regard to ConnectionManager, I must admit I've not read up on that helper as yet, currently as you can see I create a SqlConnection and command object on the fly in the DataPortal methods using a connection string held by my Authentication module (the user has to use a login screen to connect to the server/database, this builds the connection string and then makes it available to the whole engine). ...
I'm curious -- since the login screen is presented on the "client" side of the data portal, how are you getting this information to over to your module so that it is accessible on the "server" side, where the connection is actually made?
So you want a lazy loaded child object?
In that case you simply ignore that child field/property in the
create/fetch process. And you include code in your property to get the child
object on-demand:
public ChildType Child
{
if (!FieldManager.FieldExists(ChildProperty))
LoadProperty(ChildProperty,
ChildType.GetChild(this.Id)); // pass params necessary to identify child
return GetProperty(ChildProperty);
}
Then in your insert/update/delete methods, you need to use the
FieldExists() method to determine if the child is there, and if so, then
insert/update/delete its data. If you use FieldManager.UpdateChildren() to
update your child objects it will do the FieldExists() check for you.
Rocky
From: sroberts
[mailto:cslanet@lhotka.net]
Sent: Monday, February 02, 2009 4:22 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: RE: Peer review of my DataPortal code
required
Thank you for your replies so far Rocky, I'm almost 100%
happy that my property loading/unloading methods are correct now.
However the final issue I would like resolving is concerning the
initialisation/loading/updating of the child object collection, which are the
lines in blue concerning QuotationItems.
Am I correct to CREATE and FETCH this property as Nothing ? (I did this because
I didn't want an 'empty' list nor did I want to have to retrieve the data until
it was actually called for via the property Get.
Sorry, maybe offtipic but..
That reminds me:
Using the ObjectFactory i can't access the FieldManager.FieldExists() that easy.
PS: Yes, i'm using lazy loading combined with the ObjectFactory, it works perfectly for fetching.
Copyright (c) Marimer LLC