M
Michael S
Can you write DLINQ that works with both stored procedures and normal
tables without changing the DLINQ query?
In other words, if in my app I write something like:
var data = from s in SOMETHING where ...
can SOMETHING for one database server be a stored procedure, and for
another be a table, or will it be locked to one type or the other?
Hmm. Stored Procedures maps to methods on your DataContext, so it can't be
easily compared.
But for a more general answer, SOMETHING can be anything that implements
IEnumerable<T> like an Array or a List.
For more complex structures LINQ works if it has a provider for it, i.e that
has a custom implementation of IQuerable<T>. Take xml for instance, it can
be queried using LINQ by using System.Xml.Linq.
LINQ is so powerful, that you can even make join a database, a list and a
xml-document in one single query and also group them.
I ask because in some environments, data separation is done with tables
and sql in a data layer for one type of database, and stored procedures
for another.
Well this is a matter of taste.
You can always map all your stored procedures to a DataContext, but then you
are not really making much use of linq.
The whole point of separating data and code is that you can change the
implementation of one without affecting more than one layer up. In this
case it looks, but I could be wrong, like you've pulled details about the
database implementation directly up into the application.
Some people like the idea of keeping all sql in the database in form of
stored procedures.
One argument would be that you can make changes in your schema and not
affect applications.
In my experience this never happens. Typically it is always the application
that changes, that then demands changes in the database. Maybe for a
enterprisy system with many application sharing the same database, things
might be different.
I mostly work with one appliction, one database.
Consider the system I am working on now.
We got a 3 layer architecture on 2-tiers.
-- tier 1
ASP.NET web-site. - presentation
LINQ DAL .dll - business logic / rules
--- tier 2
SQL Server 2005 - data / schema
As by not using stored procedures we have really seperated data and code. =)
Personally I like this, if we also have the power to force one or the
other.
Well that would be easy, just don't use plinq. =)
But maybe the OP has a point. I think some low-level classes are missing in
..NET
It would be cool if .NET could sport a red-black-binary-tree, and why not a
balanced B-Tree.
Also, it would also be a good thing if there different sorting algorithms
already implemented instead of just '.Sort method uses quicksort'.
Well, there are always third party components.
- Michael Starberg