Aspiring Architect - Web cast series

With all this heat, I almost wrote "perspiring". Why not beat the heat, and stay cool inside while watching these web casts from MS Canada targeting aspiring architects. With the predicted shortage in IT in the upcoming years, we're sure to see an influx of junior resources into our industry. This is a good opportunity for developers to transition into architecture roles to leverage their existing skill set.

The Aspiring Architect Series 2008 builds on last year’s content and covers a number of topics that are important for architects to understand. So it would be a great idea to watch last year's recordings if you haven't already. Links are available here:  http://blogs.msdn.com/mohammadakif/archive/tags/Aspiring+Architects/default.aspx .

Upcoming sessions are as follows:

June 16th, 2008 – 12:00 p.m. to 1:00 p.m. – Introduction to the aspiring architect Web Cast series

http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032380836&Culture=en-CA

June 17th, 2008 – 12:00 p.m. to 1:00 p.m. – Services Oriented Architecture and Enterprise Service Bus – Beyond the hype

http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032380838&Culture=en-CA

June 18th, 2008 – 12:00 p.m. to 1:00 p.m. – TOGAF and Zachman, a real-world perspective

http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032380840&Culture=en-CA

June 19th, 2008 – 12:00 p.m. to 1:00 p.m. – Services Oriented Architecture (Web Cast in French)

http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032380842&Culture=en-CA

June 20th, 2008 – 12:00 p.m. to 1:00 p.m. – Interoperability (Web Cast in French)

http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032380844&Culture=fr-CA

June 23rd , 2008 – 12:00 p.m. to 1:00 p.m. – Realizing dynamic systems

http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032380846&Culture=en-CA

June 24th, 2008 – 12:00 p.m. to 1:00 p.m. – Web 2.0, beyond the hype

http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032380848&Culture=en-CA

June 25th, 2008 – 12:00 p.m. to 1:00 p.m. – Architecting for the user experience

http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032380850&Culture=en-CA

June 26th, 2008 – 12:00 p.m. to 1:00 p.m. – Conclusion and next steps

http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032380852&Culture=en-CA

Follow up on Entity Framework talk at Tech Ed 2008

Last week at TechEd I gave a talk about building data access layers with the Entity Framework. I covered various approaches from not having a data access layer at all, to fully encapsulation of the entity framework - and some hybrid approaches along the way.

I gave the first instance of this on Tuesday and then a repeat on Thursday.

To those who saw the first instance of this on Tuesday....

you unfortunately got an abbreviated and disjointed version for which I apologize. After I queued up my deck about 15 minutes prior to the talk I left the room for a minute while people filed in and while I was out, one of the event staff shutdown my deck and restarted it running from a different folder on the recording machine and didn't tell me. I was about 1/3rd into my presentation when I realized that I had the wrong version of the deck. At the time, I had no idea why this version of the deck was running so I wasn't going to fumble around looking for the correct one. Given a change in the order of things - I'm not sure if changing decks at that point would have made things better or worst. I still had no idea why this had happened when I gave the talk again on Thursday but when the same thing almost happened again - this time I caught the event staff shutting down my deck and restarting it again (from an older copy). Bottom line, sorry to those folks who saw the earlier version.

The complete deck and demo project is attached. It is a branch of the sample that is part of the Entity Framework Hands on Lab that was available at the conference and which is included in the .NET 3.5 Enhancements (aka SP1) training kit. You can will need the database for that project which is not included in my down.

Download the training kit here.

 

Live vs. Google: My Personal Verdict

About a month ago, Live.com released an update to their search engine and I took it upon myself to write down my observations of Live as compared to Google. Although the features seemed to be a pretty good leap in many areas, I concluded that the only way to see which one was better was to change my default engine to Live.com for a week or two and give it a try.

Well, it's been a month now and Live.com is still my search engine. It's not like I didn't stop using Google however. I would say that perhaps 10% or less of the time, I felt frustrated by not finding what I was looking for on Live.com and cross-searched Google.com. Of those cases, I would say only half of the time, I found something useful on Google.com that wasn't found on Live.com. These aren't hard numbers, just an anecdotal feel of my experience. When Google.com was my default search engine, my failed searches were likely in the same order as was Live.com's ability to result in something useful where Google.com did not.

So the verdict for me is that in the area of core test searches, the differences were negligible. At no time did I feel that live.com's performance was slower and I always found the image, video & map search to be superior in Live.com. These features alone for me are reason enough to leave Live.com as my default for the time being.

ObjectSharp is going to experiment with some Live.com ads. I'm not expecting any kind of serious traffic to come through ads on Live.com so this is mostly a research project to get familiar with their ad engine.

Essential MS Subscription for Mac-aphile Designers

Are you a design & mac user in a Windows Development Shop? Are they eyeing your Mac and measuring your desk to outfit you with a new PC? Over your cold dead corpse I bet. No worries. You owe it to yourself to check out the Microsoft Expression Professional Subscription.  Yeah, you could run Bootcamp but then you'd loose the OS X & Quicksilver goodness while you paid the bills.

This annual subscription's most important piece of software isn't made by MS: Parallels Desktop for Mac. Parallels will let you run Windows Vista or Windows XP (also included with the subscription) without leaving OS X - better yet with Expose, your desktop will be unified. And with the SmartSelect feature, you'll be opening Mac or Windows files in the OS of your choice automatically. Edit XAML files in Expression Blend (also include) in Windows, but open JPEG's in Photoshop in OS X - regardless from which OS you launched the file from. Very cool.

Here's the complete list of included software

                • Expression® Studio
                  Which includes Expression Web for aspx/css/html stuff, Blend for WPF/Silverlight/XAML stuff,  Expression Design for illustrations & graphics, Expression Encoder for media encoding, and Expression Media for asset management.
                • Visual Studio® Standard
                  Just in case the .NET guys make you check stuff into source control.
                • Office Standard
                • Office Visio® Professional
                  For those workflow diagrams and ugly mock ups that the dev guys send you.
                • Windows® XP
                • Windows Vista® Business Edition
                • Virtual PC
                • Parallels Desktop for Mac

And just to make things even easier, they've already included some pre-configured virtualized servers in the box as well - that will save you some time. Current pricing is about $1000 USD for the first year. This won't be available for a few weeks, but visit here to learn more.

And if you're trying to learn more about WPF and Silverlight, check out our new Windows Presentation Foundation (WPF) for Developers & Designers course. Rob Burke, our User Experience (UX) practice lead talks more about this course here. And finally, check out Rob Windsor's post on our Summer Seat Sale to learn how to save up to $500 on our training this summer.

DevTeach Toronto - in the bag - see you next year...

Well it's just 1 week since DevTeach came to Toronto for the first time. What a great conference and it was my pleasure to be involved as a speaker, track-chair and attendee. The conference organizer Jean-Rene Roy just sent me a note with some of the comments from the overall evaluations. If you didn't attend this year, here's some reasons why you may want to next year:

Great conference! I especially enjoyed the up and personal nature of the conference. I was able to talk with the presenters. I spent most of my time at the agile track. Having topics that are rarely dealt with at user groups was a bonus. I enjoyed all the sessions I attended. The venue was great and the attention to little details, e.g., afternoon ice cream was appreciated.

Jean-René, thank you SO MUCH for bringing DevTeach to Toronto. It was fantastic and I will go again. Your tech chairs did a great job choosing sessions for each track. While I especially enjoyed the Agile sessions, I attended something from each track and the variety was good.

An outstanding conference! All the speakers I saw were terrific — affable, down-to-earth, talented, incredibly knowledgeable. The sessions were entertaining as well as in-depth and honest — no BS, no company line. I also met many people and had many interesting and thought provoking discussions outside the classrooms, and came away with new knowledge, ideas and inspiration. “Training you can’t get anywhere else” is an understatement.

Most of the speakers tell us 'why' and 'so what' instead of 'how'. This is what I expected and is good for developer in the long run. Please let speakers know this is good.

This is an excellent conference. I feel I updated my skills intensively effectively during these 3 days. I believe it will become a key event in .net area.

DevTeach was an amazing experience, especially for first timers. It was a good way to network with people in the industry, learn new techniques, make friends and bring home stories.

This was my first DevTeach and if I have any say in the matter, won't be my last. I had a great time, the sessions that I attended were top notch for the most part. Jean-Rene and his team deserve a hugh pat on the back for their efforts. What-ever they're getting paid - isn't half enough

What can I say. You'll definitely see me next year. I hope its still in Toronto. This was one of the BEST training conferences I've been on in quite some time. The "take-away's" from all the sessions were astounding. My mind is still spinning. Anyway, great job, nice prizes, great orgranization, absolutely no negative thoughts or comments.

This was a fantastic experience, MUCH better information than what I got from TechEd last year. TechEd's information was very visionary, things I can talk about now but not use for a few years out. DevTeach taught me things and gave me ideas I can use NOW! I LOVE THAT! The presentators were awesome, professional and very gifted at presenting their material. The only suggestions I would make are to have hot food every day (cold cut sandwiches are fine, even suggested for people at the Pre/Post Con but not for the actual event). More evening sessions (like at TechEd). I would have liked to have seen a presentation on MSBuild. PS You should have a value for the drop down of NA for hotel and accomodations if you didn't stay at the hotel.

Status Update on Toshiba Portege M400 Tablet + Vista

It's been awhile since I've posted any updates on my Toshiba M400. Over the past year, my experience running Vista has improved greatly and I've been surprised with my efforts on extending the useful life of this machine. For the record, it's > 2 years old for me now which is starting to breaking records for me now - I normally can't go much more than a year without an upgrade. The bottom line is with things the way they are now - I'm quite happy with the machine and haven't really envied anything on the market.

  • I'm running the latest 3.60 bios which is pretty stable now, having not been updated since it's release in July 2007. Although I can't get to page 3 in the bios settings  (it locks up when I do that) things are working quite well.
  • I upgraded to 4Gb of Ram. A little over a year ago I looked into this and it was going to set me back $1500+. This past march, it only cost $100. This probably had the single biggest improvement on usability in Vista. I was surprised that going into vista's Computer properties screen - it actually showed 4gb - and yes, running under 32-bit. I could tell in Task Manager that I was only getting 3.25 - but I was still surprised. At some point a windows update came through and now it only shows, correctly, 3.24gb. The bottom line here though is that for $99 - nobody should hesitate - the pay back was huge in terms of responsiveness.
  • I also upgraded the internal wifi from 802.11g to 802.11n. This installation is not much more difficult than replacing the Ram and involves removing the keyboard which is quite simple. The only tricky part is getting those bloody antennae wire's snapped onto the circuit board. This upgrade cost $40 for the intel 802.11n card and installed in less than 30 minutes. I also upgraded my home router in conjunction with this upgrade. The throughput improvement was huge. My signal strength also improved greatly. My home office is in the basement (where my router is) and when I'm not in there, our family room is 1 floor up and somewhat diagonal from the home office. There are 2 or 3 walls through a stairway and a floor between where I normally sit and the router so signal strength was always marginal. No problems now and speed is at least doubled.
  • I had purchased 2 100gb sata drives (7200rpm) to replace the internal drive and to put in the HDD Adapter tray. This is great for running VPCs. I've just ordered a new 7200rpm 320gb drive since I was finding 100gb a bit tight. I was hoping that performance of SSD would have come along faster (and the price too) but I'll have to wait for that. New drive is still a week or two away.
  • I had my two laptop batteries refurbished at Ink Jet Sales. They take your batteries - put in new cells, for $85 and a 1 week wait. I wouldn't say they are as good as when I first bought them, but they are pretty darn close. Compared to the $200 Toshiba wants for new ones, this was a good deal. I also purchased an external toshiba charger that can charge 2 batteries externally from the laptop.
  • As you may have recalled, my CMOS battery had mysteriously died and my clock was never right. This happened around the upgrade to Vista so I was a bit suspicious. It's amazing how many bad things happen when your clock is a day or two old. Many servers won't let you connect to them, VPCs get all wonky, etc. It was really hard to find a replacement battery - and this being a US laptop, living in Canada - the warranty fix was going to take close to a week. I could never do without my laptop for that long. Yesterday however, a battery showed up and our trusty IT magician, Max, took apart the laptop and got it back together. The RTC battery is nestled under the motherboard so he literally had to take apart everything. The step-by-step instructions here were invaluable. It took him about an hour and all things went smooth. I wasn't 100% convinced it was the battery that was causing the clock issues - but 24 hours later and it seems to have been the fix that was required. A nice side effect is that this repair requires the LCD and the hinge to be disconnected. After reassembly - the hinge is now as tight and firm as it was the day I bought it. It had become a bit loose over the past couple of years.
  • I picked up a new 28" monitor a few weeks ago for the home office and had not stopped to think if the M400 could drive the 1920 x 1200 resolution until I started unpacking it. I hadn't used an external monitor for over a year and the last time - I couldn't get it to drive the 1600x1200 resolution of the monitor I had at that time. A bios update fixed that - but I still couldn't run Vista with Aero Glass when both displays were active. Much to my surprise however is that it has no problems with the full 1920x1200 resolution with Aero Glass. I suspect that new graphics drivers from Intel + the left over ram between the 3.25gb used by Vista and the 4Gb available has something to do with that.

All in, I'm very content with this laptop these days. Performance is great and you can't beat the package size. I still have troubles finding a 12.1" laptop with 1400x1050 resolution these days. Heck, I have troubles finding this in 13 and 14 inch models as well.

I use just about all of the features of this machine on a day to day basis including the tablet functionality and I've fallen in back in love with this machine.

My only complaint - and it's my fault, is that the screen is quite scratched up and pitted these days. If somebody has a M400 with the 1400x1050 laptop that isn't working (but the screen is in good shape) I'd love to buy it off you. I know a lot of MS employees have (or had) this machine - so if any of you have one lying around and they want to get rid of it - drop me a note at bgervin@objectsharp.com.

Live Search is actually getting pretty good these days!

image Live Search got a refresh recently and it's actually pretty good, dare I say may be even better than Google.

  • Performance: The load times are very snappy now and it feels pretty much on par with google performance.
  • Image Search: Functionality on Image Search has been superior for some time with the ability to size the thumbnails and I quite like the "add to scratchpad" feature but wish it was available for video and web content as well. The ability to refine the search by size, aspect ratio, colour, Style (photo vs. illustration) and Face (i.e. head & shoulders, just face, etc.) is brilliant. It's not 100% accurate, but it is still quite useful. Google can do a subset of this, but frankly, never noticed it until I went looking for it. These features are more discoverable in Live. I have to say that I'm in love with the fact that I can preview the context of the pages split screen so I don't leave my list of results. As far as relevancy goes, I'm going to have to give it a try for a week. Google does a better job finding pictures of me, but Live does a better job of finding black & whites of Darryl Sittler.  Live found 12 good b&w's of the Sitler while google found absolutely nothing of relevance. Unfortunately, Live fails my vanity image search and google prevails with more pictures of me. 
  • Video Search: I honestly have never used video search on live or google until this blog entry. Live has a nice feature where it can play videos from the results page by just hovering over the thumbnails. It can't do it for every video type, some you have to click on but it is a lovely feature when it works which from what I can tell is about 60% of the time. Google only manages to get 10 thumbnails per page where live gets twice that. Live brought back a few extra total results. It seems like google favours primarily youtube.
  • Map Search: Mileage seems to vary greatly depending on where you are searching. Live has the great integrated 3D maps with buildings, contoured terrain and birds eye view vs. google with street view as it's killer feature. For Canadians, google hasn't made any of these features available yet. Live has thrown us Canadians a few bones with birds eye view available in Vancouver, Calgary, Toronto, and Montreal. Live also gives us some traffic in Vancouver, Toronto, Montreal, and Ottawa.

    Live maps has some great directional tools as well. I like the feature where I can just click on a point and ask for 1 click directions - which will give me generic instructions on coming to a location from all major available directions/arteries. This is great if you want to include directions on an invitation but you don't know where everybody is coming from. The Live Map collection editor and the ability to easily add pushpins and draw (with distances) on the map is great.

    One thing I do like about Google maps is the ability to take a set of directions and drag segments around to tell it how I really want to get somewhere. All in all though, I much prefer (as a Canadian) Live Maps as the most


  • Plain Old Web Relevancy: Plain old web results are perhaps the most important criteria. I think this will be impossible to provide any meaningful observations after spending < 1 hour using live search. I'm going to give live a shot as my default search engine for the next week and see how it does but a few immediate observations:
    • Live wins on relevancy for the "Barry Gervin" vanity search, easily. By the bottom of the first page (items 7th-9th), Google is showing results that are irrelevant - in fact, no mention of Barry or Gervin on any of those pages.
    • Searching for some things that I know are on MSDN Forums - posted yesterday, google seems to be crawling that site faster than Live. Google still has a dedicated newsgroups search engine. I used to use this a lot more than I currently do so I have mixed emotions about live search. In fact, in some of my tests for searching things that I knew were known to exist in newsgroups, live search actually referred me to google groups - so it does appear that live is indexing the google groups search engine. I think the thing I find most appealing about google groups is not the content that it finds, but the way it presents it, showing me what group a result was found in, and then making the detailed results essentially a web based NNTP client. Live could do much more than they are doing now that's for sure, I'm just not sure that it really matters.
    • I'm making more and more use of google alerts to have things I am constantly tracking or researching searched and emailed to me. Live has no equivalent to this.

I'm going to give Live Search a trial as my default search engine for the next week or so and see how it goes. I'm optimistic.

Visual Studio 2008 SP1 Beta & SQL Server 2008

A quick heads up to let you know that VS 2008 Service Pack 1 is now available (links below). It typically takes a couple of months from this point before we'll see a final release.

This Service Pack includes new cool feature:

One interesting point is that MS is going to simultaneously ship SQL Server 2008 which actually has a hard dependency on SP1.

I thought I’d take a moment to highlight some new features that Dev’s would care about in SQL Server 2008.

  • Change Data Capture: Async “triggers” capture the before/after snapshot of row level changes and writes them to Change Tables that you can query in your app. They aren’t real triggers as this asynchronously reads the transaction log.
  • Granular control of encryption, right through to the database level without any application changes required.
  • Resource Governor – very helpful when you allow users to write adhoc queries / reports against your OLTP database. Allows a DBA to assert resource limits & priorities.
  • Plan Freezing – allows you to lock down query plans to promote stable query plans across disparate hardware, server upgrades, etc.
  • New Date, and Time data types, no longer just DateTime types that you have to manually parse out the time or date to just get the real data you want.
  • DataTimeOffset – is a time zone aware datetime.
  • Table Value Parameters to procs – ever want to pass a result set as an arg to a proc?
  • Hierarchy ID is a new system type for storing nodes in a hierarchy….implemented as a CLR User Defined Type.
  • FileStream Data type allows blobish data to be surfaced in the database, but physically stored on the NTFS file system. ….but with complete transactional consistency with the relational data and backup integration.
  • New Geographic data support, store spatial data such as polygons, points and lines, and long/lat data types.
  • Merge SQL statement allows you to insert, or update if a row already exists.
  • New reporting services features such as access to reports from within Word & Excel, better SharePoint integration

Personally, haven't spent any time with SQL Server 2008 but that's a great set of new features that I can hardly wait to start using in real-world applications.

Downloads

· VS 2008 SP1 : http://download.microsoft.com/download/7/3/8/7382EA08-4DD6-4134-9B92-8585A5B07973/VS90sp1-KB945140-ENU.exe

· .NET 3.5 SP1 : http://download.microsoft.com/download/8/f/c/8fc1fe13-55de-4bf5-b43e-375daf01452e/dotNetFx35setup.exe

· Express 2008 with SP1:

o http://download.microsoft.com/download/F/E/7/FE754BA4-140B-413C-933F-8D35FB150F12/vbsetup.exe

o http://download.microsoft.com/download/F/E/7/FE754BA4-140B-413C-933F-8D35FB150F12/vcsetup.exe

o http://download.microsoft.com/download/F/E/7/FE754BA4-140B-413C-933F-8D35FB150F12/vcssetup.exe

o http://download.microsoft.com/download/F/E/7/FE754BA4-140B-413C-933F-8D35FB150F12/vnssetup.exe

· TFS 2008 SP1: http://download.microsoft.com/download/a/e/2/ae2eb0ff-e687-4221-9c3e-9165a942bc1c/TFS90sp1-KB949786.exe

Feedback Forum: http://go.microsoft.com/fwlink/?LinkId=119125

 

The Entity Framework vs. The Data Access Layer (Part 1: The EF as a DAL)

In Part 0: Introduction of this series after asking the question "Does the Entity Framework replace the need for a Data Access Layer?", I waxed lengthy about the qualities of a good data access layer. Since that time I've received a quite a few emails with people interested in this topic. So without further adieu, let's get down to the question at hand.

So let's say you go ahead and create an Entity Definition model (*.edmx) in Visual Studio and have the designer generate for you a derived ObjectContext class and an entity class for each of your tables, derived from EntityObject. This one to one table mapping to entity class is quite similar to LINQ to SQL but the mapping capabilities move well beyond this to support advanced data models. This is at the heart of why the EF exists: Complex Types, Inheritance (Table per Type, Table per Inheritance Hierarchy), Multiple Entity Sets per Type, Single Entity Mapped to Two Tables, Entity Sets mapped to Stored Procedures or mapping to a hand-crafted query, expressed as either SQL or Entity SQL. EF has a good story for a conceptual model over top of our physical databases using Xml Magic in the form of the edmx file - and that's why it exists.

So to use the Entity Framework as your data access layer, define your model and then let the EdmGen.exe tool do it's thing to the edmx file at compile time and we get the csdl, ssdl, and msl files - plus the all important code generated entity classes. So using this pattern of usage for the Entity Framework, our data access layer is complete. It may not be the best option for you, so let's explore the qualities of this solution.

To be clear, the assumption here is that our data access layer in this situation is the full EF Stack: ADO.NET Entity Client, ADO.NET Object Services, LINQ to Entities, including our model (edmx, csdl, ssdl, msl) and the code generated entities and object context. Somewhere under the covers there is also the ADO.NET Provider (SqlClient, OracleClient, etc.)

image

To use the EF as our DAL, we would simply execute code similar to this in our business layer.

var db = new AdventureWorksEntities();
var activeCategories = from category in db.ProductCategory
                 where category.Inactive != true
                 orderby
category.Name
                 select category;

How Do "EF" Entities Fit In?

If you're following along, you're probably asking exactly where is this query code above being placed. For the purposes of our discussion, "business layer" could mean a business object or some sort of controller. The point to be made here is that we need to think of Entities as something entirely different from our Business Objects.

Entity != Business Object

In this model, it is up to the business object to ask the Data Access Layer to project entities, not business objects, but entities.

This is one design pattern for data access, but it is not the only one. A conventional business object that contains its own data, and does not separate that out into an entity can suffer from tight bi-directional coupling between the business and data access layer. Consider a Customer business object with a Load method. Customer.Load() would in turn instantiate a data access component, CustomerDac and call the CustomerDac's Load or Fill method. To encapsulate all the data access code to populate a customer business object, the CustomerDac.Load method would require knowledge of the structure the Customer business object and hence a circular dependency would ensue.

The workaround, if you can call it that, is to put the business layer and the data access layer in the same assembly - but there goes decoupling, unit testing and separation of concerns out the window.

Another approach is to invert the dependency. The business layer would contain data access interfaces only, and the data access layer would implement those interfaces, and hence have a reverse dependency on the business layer. Concrete data access objects are instantiated via a factory, often combined with configuration information used by an Inversion of Control container. Unfortunately, this is not all that easy to do with the EF generated ObjectContext & Entities.

Or, you do as the Entity Framework implies and separate entities from your business objects. If you've used typed DataSets in the past, this will seem familiar you to you. Substitute ObjectContext for SqlConnection and SqlDataAdapter, and the pattern is pretty much the same.

Your UI presentation layer is likely going to bind to your Entity classes as well. This is an important consideration. The generated Entity classes are partial classes and can be extended with your own code. The generated properties (columns) on an entity also have event handlers created for changing and changed events so you can also wire those up to perform some column level validation. Notwithstanding, you may want to limit your entity customizations to simple validation and keep the serious business logic in your business objects. One of these days, I'll do another blog series on handing data validation within the Entity Framework.

How does this solution stack up?

How are database connections managed?

thumbs up Using the Entity Framework natively itself, the ObjectContext takes care of opening & closing connections for you - as needed when queries are executed, and during a call to SaveChanges. You can get access to the native ADO.NET connection if need be to share a connection with other non-EF data access logic. The nice thing however is that, for the most part, connection strings and connection management are abstracted away from the developer.

thumbs down A word of caution however. Because the ObjectContext will create a native connection, you should not wait to let the garbage collector free that connection up, but rather ensure that you dispose of the ObjectContext either explicitly or with a using statement.

Are all SQL Queries centralized in the Data Access Layer?

thumbs down By default the Entity Framework dynamically generates store specific SQL on the fly and therefore, the queries are not statically located in any one central location. Even to understand the possible queries, you'd have to walk through all of your business code that hits the entity framework to understand all of the potential queries.

But why would you care? If you have to ask that question, then you don't care. But if you're a DBA, charged with the job of optimizing queries, making sure that your tables have the appropriate indices, then you want to go to one central place to see all these queries and tune them if necessary. If you care strongly enough about this, and you have the potential of other applications (perhaps written in other platforms), then you likely have already locked down the database so the only access is via Stored Procedures and hence the problem is already solved.

Let's remind ourselves that sprocs are not innately faster than dynamic SQL, however they are easier to tune and you also have the freedom of using T-SQL and temp tables to do some pre-processing of data prior to projecting results - which sometimes can be the fastest way to generate some complex results. More importantly, you can revoke all permissions to the underlying tables and only grant access to the data via Stored Procedures. Locking down a database with stored procedures is almost a necessity if your database is oriented as a service, acting as an integration layer between multiple client applications. If you have multiple applications hitting the same database, and you don't use stored procedures - you likely have bigger problems. 

In the end, this is not an insurmountable problem. If you are already using Stored Procedures, then by all means you can map those in your EDM. This seems like the best approach, but you could also embed SQL Server (or other provider) queries in your SSDL using a DefiningQuery.

Do changes in one part of the system affect others?

It's difficult to answer this question without talking about the possible changes.

thumbs up Schema Changes: The conceptual model and the mapping flexibility, even under complex scenarios is a strength of the entity framework. Compared to other technologies on the market, with the EF, your chances are as good as they're going to get that a change in the database schema will have minimal impact on your entity model, and vice versa.

thumbs up Database Provider Changes: The Entity Framework is database agnostic. It's provider model allows for easily changing from SQL Server, to Oracle, to My Sql, etc. via connection strings. This is very helpful for ISVs whose product must support running on multiple back-end databases.

thumbs down Persistence Ignorance: What if the change you want in one part of the system is to change your ORM technology? Maybe you don't want to persist to a database, but instead call a CRUD web service. In this pure model, you won't be happy. Both your Entities and your DataContext object inherit from base classes in the Entity Framework's System.Data.Objects namespace. By making references to these, littered throughout your business layer, decoupling yourself from the Entity Framework will not be an easy task.

thumbs down Unit Testing: This is only loosely related to the question, but you can't talk about PI without talking about Unit Testing. Because the generated entities do not support the use of Plain Old CLR Objects (POCO), this data access model is not easily mocked for unit testing.

Does the DAL simplify data access?

thumbs up Dramatically. Compared to classic ADO.NET, LINQ queries can be used for typed results & parameters, complete with intelli-sense against your conceptual model, with no worries about SQL injection attacks.

thumbs up As a bonus, what you do get is query composition across your domain model. Usually version 1.0 of a convention non-ORM data access layer provides components for each entity, each supporting crud behaviour. Consider a scenario where you need to show all of the Customers within a territory, and then you need to show the last 10 orders for each Customer. Now I'm not saying you'd do this, but what I've commonly seen is that while somebody might write a CustomerDac.GetCustomersByTerritory() method, and they might write an OrderDac.GetLastTenOrders(), they would almost never write a OrderDac.GetLastTenOrdersForCustomersInTerritory() method. Instead they would simply iterate over the collection of customers found by territory and call the GetLastTenOrders() over and over again. Obviously this is "good" resuse of the data access logic, however it does not perform very well.

Fortunately, through query composition and eager loading, we can cause the Entity Framework (or even LINQ to SQL) to use a nested subquery to bring back the last 10 orders for each customer in a given territory in a single round trip, single query. Wow! In a conventional data access layer you could, and should write a new method to do the same, but by writing yet another query on the order table, you'd be repeating the mapping between the table and your objects each time.

Layers, Schmayers: What about tiers?

thumbs down EDM generated entity classes are not very tier-friendly. The state of an entity, whether it is modified, new, or to be delete, and what columns have changed is managed by the ObjectContext. Once you take an entity and serialize it out of process to another tier, it is no longer tracked for updates. While you can re-attach an entity that was serialized back into the data access tier, because the entity itself does not serialize it's changed state (aka diff gram), you can not easily achieve full round trip updating in a distributed system. There are techniques for dealing with this, but it is going to add some plumbing code between the business logic and the EF...and make you wish you had a real data access layer, or something like Danny Simmons' EntityBag (or a DataSet).

Does the Data Access Layer support optimistic concurrency?

thumbs up Out of the box, yes, handily. Thanks to the ObjectContext tracking state, and the change tracking events injected into our code generated entity properties. However, keep in mind the caveat with distributed systems that you'll have more work to do if your UI is separated from your data access layer by one or more tiers.

How does the Data Access Layer support transactions?

thumbs up Because the Entity Framework builds on top of ADO.NET providers, transaction management doesn't change very much. A single call to ObjectContext.SaveChanges() will open a connection, perform all inserts, updates, and deletes across all entities that have changed, across all relationships and all in the correct order....and as you can imagine in a single transaction. To make transactions more granular than that, call SaveChanges more frequently or have multiple ObjectContext instances for each unit of work in progress. To broaden the scope of a transaction, you can manually enlist using a native ADO.NET provider transaction or by using System.Transactions.

Live Search Maps - now with Bird's Eye View in Toronto

image

It's amazing what MS will give you, if you give them a Team Canada Hockey Jersey.

More Posts Next page »