Extending the ADO.NET Entity Framework
Posted On Tuesday, March 24, 2009 at at Tuesday, March 24, 2009 by Ben HLast night I gave a presentation on the ADO.NET Entity Framework at the Denver Visual Studio User Group. It was a great discussion and the questions from the audience helped me tell the story I was trying to tell. That story is that the Entity Framework is a great data access tool. It’s extendable and in turn flexible enough to meet the needs of the small point solutions to the enterprise caliber solutions. What I really like about it is the ability to start simple. Let’s get a solution up and running and then go back and extend\refactor certain areas to improve the architecture and\or performance. That’s not saying we shouldn’t do some design work up front, but let’s start by getting a solid solution built and then add on features and improvements in the future.
Sometimes I think architects focus too much on creating the perfect architecture instead of creating a flexible one. The solution just needs to work given the current requirements. Beyond that, it also needs to be flexible so it can change when new requirements and features get defined. EF lends itself very well to flexibility and extensibility.
The zip file below contains the final solution. That solution has all the extensions we did to the context as well as the entities in the context. It also includes a basis for a validation framework. The validation framework could use some tweeks to make it better. I leave that to you and your creative minds.
The zip file also contains a SQL script that will quickly and easily create the sample DB for you. Both the schema and the data. All you need to do is change the location of the DB file (.mdf) and the log file (.ldf) in order to run the script. Once you get the DB created you will have to change the server name in the connection string located in the web.config. After that everything should run great. Here is the zip:
I hope that you enjoyed the talk. If you would like the step by step guide to creating the initial model and setting up the inheritance please visit Rob Bagby’s blog of EF.
LINQ : The DBA vs the Developer
Posted On Wednesday, March 04, 2009 at at Wednesday, March 04, 2009 by Ben HAt the Rocky Mountain Tech-Trifecta Eric and Johnson and I did a session related to this topic. David Yack wanted us to do something that he could use to promote the session during his keynote. So, we went over the top and created this video. Enjoy!
.NET Events in Colorado
Posted On Wednesday, January 28, 2009 at at Wednesday, January 28, 2009 by Ben HI know January is almost over, but to me the year is still new. I wanted to inform everyone about all the awesome User Groups and Community events in Colorado.
One of the most exciting upcoming events is the first ever Rocky Mountain Tech Tri-Fecta on Saturday, Feb. 21. I cannot explain how cool this event is going to be! It’s basically an all day geek fix. There will be sessions related to .NET development, SQL Server and Windows Server. So, if you work with MS products or know someone who does this is the event for you. We have tons of speakers (Scott Hanselman is coming!) from all over the country and many who work for Microsoft and have inside info you cannot get anywhere else. If you like what you are hearing please be sure visit the www.rmtechtrifecta.com site to register for the event to reserve your spot.
Next I wanted to let people know about the South Colorado .NET User Group. I have taken over the leadership of this group from Julie Yack. Julie Yack, David Yack and David Milner round out the leadership team for this group. Next Tuesday we have Kathleen Dollard coming down from Ft. Collins to talk about rethinking Object Orientation. SHould be great! Please check out the link above to get more details.
Here are the links to all the MS related user groups I can think of in Colorado.
Denver Visual Studio User Group
North Colorado .NET User Group
Colorado Springs SQL Server User Group
Colorado Springs Windows User Group
Rocky Mountain Windows Technology User Group
Please let me know if I missed a group.
Virtual Conference Day 3
Posted On Friday, November 07, 2008 at at Friday, November 07, 2008 by Ben HToday was another great day at the vConference. I attended some great sessions over the course of these three days and now I'm excited to go back and watch the ones I missed on demand. I hope everyone had as much fun as I did with the conference!
I did finally get my hosting situation figured out. That means I can get my slides and demos out here for people to download. I do believe that the vConference site will have this stuff posted eventually, but in case they don't here you go:
SharePoint:
.NET:
Virtual Conference Day 2
Posted On Thursday, November 06, 2008 at at Thursday, November 06, 2008 by Ben HDay 2 of the conference was just as good as day 1. We had great sessions all day long. I attended a bunch of the sessions and had some great conversations with many of the attendees. One of the issues we ran into today was the demos where not available. I was going to post them here, but I'm having some issues with my ISV and getting the files to the server. I will post them ASAP.
In the mean time, enjoy the rest of the conference.
.NET Developer Virtual Conference : Oct. 28 - 30
Posted On Wednesday, August 20, 2008 at at Wednesday, August 20, 2008 by Ben HJust wanted to let everyone know that I am lucky enough to be a presenter at this years SSWUG.org .Net Developer Virtual Conference in October. This is a really cool idea where all the sessions are pre-recorded and on the days of the conference you can login and watch from the comfort of your ergonomically correct cubicle chair. Maybe you can talk your boss into giving you the days off and you can watch in your PJs from your couch. Either way you don't have to incur the time or the cost of traveling to an in-person conference. This is a plus for those of you that are "Dungeon" coders. You can get all the great content of the conference without leaving the "Dungeon" and being forced to socialize with other people. That can be uncomfortable...
Seriously, there is some great content from some of the top presenters in the industry on deck for this conference. I'm just glad I get a free login so I can attend some of the other presenters sessions. Speaking of cost, you get all three days for just $100. If you can't sell this to your boss you're never getting any training EVER.
Again there are some great topics and presenters so please use this link to check out the sessions and the presenters for this conference:
.NET Developer Virtual Conference
There are also 3 other Microsoft related virtual conferences scheduled for the fall. Use this link to find out about all the conferences from SWWUG.org:
Are ADO.NET Datasets dead?
Posted On Wednesday, July 30, 2008 at at Wednesday, July 30, 2008 by Ben HIf you are plugged in at all to the Microsoft world you have been seeing more and more LINQ and ADO.NET Entity Framework buzz. You can't go to a conference or attend a User Group meeting without discussing one of these new data access technologies. I'm not saying that's a bad thing... Unless you are a Dataset, Datatable or Dataview.
I wrote a post back in May trying to shed some light on when to use which technology. You might want to read that post and the comments before reading on. In that post I stated that if you are creating new applications or just adding on features to your current app I would use LINQ or EF instead of ADO Datasets. There are many reasons. Here are the most compelling reasons to use LINQ and EF.
- Objects - The nicest thing about LINQ and EF is they provide some of the foundations for Object Oriented programming. They literally force you to think and work in terms of objects and collections of objects instead of rows and tables of rows. By setting up this foundation, these technology allow for the application to grow and use some of the more complex OO concepts without doing tons of work to fill and save objects from Datasets. So, start simple and as the requirements on your application change you can use some more complex OO topics to solve those problems.
- Memory - There are two schools of though on this topic. Some people like to pull all the data back into memory and then work with it there. Others don't like to fill memory with data that might not ever be used. LINQ and EF allow for both. When you build your LINQ and EF models you can use stored procedures same as you used to with Datasets and bring back the whole table if you desire. Or you can use the LINQ syntax to do filtering and sorting, which uses the power of the relational database engine to get only the row(s) you need. To me it is compelling to have the flexibility that LINQ and EF give me.
- Performance - We can go round and round about the performance implications here. People say stored procedures are faster because they are pre-compiled, but with the new technologies these LINQ queries are cached and optimized and the difference is often minimal. To me this is the 80\20 rule. 80 percent of my queries will run the same or faster in LINQ and EF than they do in a SP. The other 20 percent of my queries will run faster in stored procedures. So, use both. LINQ and EF allow for using SP or the LINQ syntax. Plus, with LINQ you can bring back only the columns you need which can improve performance as well. I'm not saying quit using stored procedures, but instead of just blindly using them because that's what you've always done, step back and analyze your requirements to see if it's worth it.
- Interop with Other Object Collections - The other benefit of working with LINQ and EF is that you can join your data objects with other object collections. If you've seen my talk on LINQ and the demo related to joining my SQL data with file data retrieved using the System.IO objects. It is so easy and would require lots of work with Datasets.
There are many more reasons out there, but these are a few of the ones that are most important to me. Any one else want to add?
Data Access Technologies - Should I use ADO, LINQ, nHibernate or the Entity Framework?
Posted On Tuesday, May 20, 2008 at at Tuesday, May 20, 2008 by Ben HI came across this blog post today that explains the differences between these data access technologies. However, it does not give a definitive answer on when to use which technology. That's because it depends on so many factors. My advice is to keep it simple.
Let me expand on the different technologies and provide some guidelines on when to use them:
Classic ADO.Net - In my opinion ADO.Net is a dying breed. As a developer you need to know it for maintenance purposes, but any new features or products should be designed using LINQ or EF\nHibernate. Some people might not agree with me here, but again this is my opinion. The only caveat is to make sure the target environment supports the 3.5 Framework. If the systems people will not let you install 3.5 on the server or end user's machine then LINQ and EF will not work.
LINQ (LINQ to SQL) - As the blog post on this states, LINQ currently only supports SQL Server. There are tons of open source projects that do LINQ to other things, but the only MS supported database backend is SQL Server. For many of us, that is just fine. If you know you need to support other DB platforms you can move on to EF\nHibernate now. If you're pretty certain the only DB backend is going to be SQL Server then the decision between LINQ to SQL or EF\NHibernate comes down to architecture. EF\nHibernate are full blown ORM tools, meaning they include many additional features (Inheritance, complex types, multiple data sources, etc) over and beyond what LINQ to SQL provides. So, if you are using SQL Server and the application design is not overly advanced or complex. I'd use LINQ to SQL.
EF\nHibernate - I lumped these two tools together because they are both ORM tools. They provide support for many advanced and complex concepts in software design. Using these advanced features is great if you are building a large enterprise, public facing or consumer use application. However, for many applications these tools can be overkill and end up taking too much time to design. That being said there is one thing that often gets overlooked, the fact that you can use these tools to do one to one mapping similar to the way LINQ to SQL does. So, if you need to support mulitple DB backends, but you don't want to use the advanced features you can do so.
In summary, if you are building a simple application that is going to use SQL Server as the DB backend, use LINQ to SQL. If you are building a simple application that needs to support a DB backend other than SQL Server, use EF or nHibernate and do one to one mapping between your entities and your DB tables. If you are building a large application that requires some complex architecture, use EF or nHibernate. Don't use ADO.Net for any new projects unless the target environment does not support the .Net 3.5 Framework. However, I don't think it is necessary to go back and rip out all your ADO.Net code and replace it with something else. Just be patient and use the new stuff with new projects.
LINQ Demo from Heroes Community Launch
Posted On Thursday, April 10, 2008 at at Thursday, April 10, 2008 by Ben HSorry for the lack of post lately. My family just finished moving into a new house and my life has been a whirlwind. Hopefully, we are on the downside and I can start focusing on Technology related stuff again. Honestly, hanging curtain rods is not my idea of a great weekend...
Anyway, I wanted to drop the demo code, DB script and slides out here so people can take a look. I had a great time doing the presentation with Eric Johnson. Even though Eric is a DBA he is still a good guy. Who knew that some DBAs actually have a soul? Seriously though, I've been hanging out with the Springs SQL Server User Group for awhile now and they are a great resource when I come across SQL related issues. Check them out if you haven't already.
Here is the Zip of all the materials from my session:
CS Techcasts - SQL Server and LINQ Webcast\Podcast
Posted On Tuesday, March 11, 2008 at at Tuesday, March 11, 2008 by Ben HLast Thursday at PASS Camp in Denver I participated in a live webcast\podcast related to SQL Server topics. Why was a developer involved? Well I don't want to spoil the surprise so you'll just have to watch. Wether your a SQL Server expert or just know enough to be dangerous this is a great informational cast. Check it out!
LINQ to SQL is the Devil?
Posted On Sunday, March 09, 2008 at at Sunday, March 09, 2008 by Ben HLast Thursday I attend the SQL Server Pass Camp in Denver. As one of the only developers there I got a lot of negative vibes related to LINQ to SQL and ADO .Net Entity Framework. DBAs seem to think any tool that generates SQL statements is evil. I have to admit I agree with them. Even if the generated SQL is flawless, it can take away the DBAs ability to tune performance.
However, I think there is a happy medium that will help DBAs sleep at night and still give the developers the flexibility they need. It's the same answer we've been using for years, Stored Procedures. If you think about it, developers have had the option of running SQL queries directly against the DB for years using inline SQL statements. So, nothing has really changed. LINQ to SQL and the Entity Framework both have full support for stored procedures. Use Stored Procedures for all updates, inserts and deletes. You can also use stored procedures to retrieve data. However this takes away some of the the flexibility LINQ to SQL and the Entity Framework provide to the developer. So, for reads I recommend using views. They allow DBAs to restrict the columns visible and also provide an extra layer of security.
All the feed back I received from DBAs was positive once I explained that stored procedures and views are still the best practices for these new technologies. They were also put to ease when I reminded them that this really is nothing new for them.
So to answer the question, LINQ to SQL is not evil.