- I would use OpenID as the login provider
- I would use Linq to Sql as the Data Access Layer
First though, I need to admit something: I was hesitant about adopting Linq. I mean seriously, look at the stuff. You do some fancy hand waving and all of a sudden, you have a data layer? It just seemed so... unnatural.
And I was right, it fundamentally is some fancy hand waving, and then you have a datalayer. It is unnatural, but it is also awesome!
So, what happens is that I build myself my data structures in SQL Server. I then use the diagram tool to make sure that all those fun Primary & Foreign Key and associated relationships are there. At that time, I drag and drop those tables onto the Linq designer surface. My computer freezes for a moment as it does some crunching and then I have data access stuff.
I'm being quite literal here; and it's fast. Fast to use, and fast to develop against.
Consider, I have a Customer object as part of my DataContext. The steps I would take, to save my changes to this are thus:
- Instantiate an instance of the Data Context
- Check to see if the Customer exists in the Data Context
- If yes, return that, if no return nothing
- If nothing, instantiate an new instance of a Customer, and add to Customers collection
- Make changes to the properties of Customer
- Update the Data Context
For Linq, it's this:
Dim db as DataContextThat is it.
Dim Cust As Customer
Cust = (Select d From db.Customers Where d.Id = MyIdVariable ).SingleOrDefault
If Cust Is Nothing Then
Cust = New Customer
db.Customers.InsertOnSubmit(Cust)
End If
Cust.CustomerName = txt.Text
db.SubmitChanges
What's happening there is I'm instantiating the datacontext, grabbing either the Customer object I want, or it returns Nothing. Checking for nothing, and if so, instantiating a new instance of the Customer object, and adding it to the DataContext, and then changing values via properties.
It's clean and straightforward, and utterly awesome.