Extending the ADO.NET Entity Framework

Last 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:

EFDemoes.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.

XRM Taking Off

At Colorado Technology Consultants (CTC) we do quite a bit of work with MS Dynamics CRM.  One of things Julie and David Yack are big on is the concept of XRM.  If you are not familiar with it, it extends the Customer Relationship Management side of MS CRM to any kind of Line of Business application.  MS CRM is a very customizable product and can be extended to be used for many non CRM type applications.

That being said CTC is kind of the XRM gurus right now.  Dave’s book on the subject is actually being used on MSDN in some places as reference material.  You can purchase the entire book, including a usable .NET framework that comes ready to use with the book, here.  Julie is starting up an XRM Virtual User Group that will consist of monthly Live Meetings related to the XRM space.  The user group site is actually built on top of MS CRM Live and hosted on Azure in the cloud.  Please visit the site to check out an impressive display of XRM and to register with the group.

XRM is becoming one of the hot Dynamic products.  So, you next step is to attend the XRM Virtual User Group meetings and learn how to use XRM to solve your software needs.

Posted in Labels: , | 0 comments

Iterating Through a Collection Using Reflection

I ran into an issue today using reflection.  I was getting properties on a object using the following code:

   1: Type argsType = args.GetType();
   2: PropertyInfo piResults = argsType.GetProperty("Result");
   3: object result = piResults.GetValue(args, null);

This works great if the object you are trying to retrieve is just a simple object.  However, what if the object in question is a collection of some sort?  This does not work because the results of type object are useless.  The key to solving this issue is to use the IEnumerable interface.  Here is the code to solve my issue:

   1: Type argsType = args.GetType();
   2: PropertyInfo piMessageList = argsType.GetProperty("Result");
   3:  
   4: IEnumerable Messages = (IEnumerable)piMessageList.GetValue(args, null);
   5:  
   6: Type objType;
   7: PropertyInfo objResults;
   8: foreach (object thisMsg in Messages)
   9: {
  10:     objType = thisMsg.GetType();
  11:     objResults = objType.GetProperty("Message");
  12:     Processmessage(objResults.GetValue(thisMsg, null).ToString());
  13: }

Notice on line 4 I’m casting the results from the GetValue method to an IEnumerable.  From there I can run through the objects and use reflection to pull out the individual properties.  Not the cleanest approach, but it works well if you are in a situation where the type of your results are not known to the consumer.

Posted in Labels: , | 0 comments

Circular Reference Error in Silverlight

I’m working on some demo projects for some presentations I’m doing for the Spring SSWUG .NET Development Virtual Conference.  More on the conference later.  While working on the demo code I ran into an issue when trying to reference one of my base classes.  I kept getting an error related to a circular reference.  I checked all my references in both projects and could not find the issue.  Finally, David Yack gave me a pointer that fixed my problem.  It was a problem with the project dependencies.  To fix this you need to change the dependencies.  To change the dependencies right click on the solution and select “Project Dependencies”.

ProjectDependencies

Make sure that the project you are referencing does not have a reference to the current project.

Posted in | 3 comments

LINQ : The DBA vs the Developer

At 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!

Rocky Mountain Tech-Trifecta : A Week Later

It’s been a week since the Rocky Mountain Tech-Trifecta and I’m still getting caught up and processing everything that I learned there.  I presented a couple sessions and I also attended a bunch of sessions.  Fun stuff.  I think the event was huge success.  Thanks to my employer Colorado Technology Consultants, Inc. for letting me spend so much time volunteering for the event.  A special shout out to Julie Yack for all the time and effort she put in.  Please visit her blog at http://julieyack.blogs.com for a couple cool pictures from the event as well as some fun facts.

As stated above, I did two sessions at the Tri-Fecta.  The code and slides are below.  Please email me any questions or comments to benh@coloradotc.com.  You can also catch up with me on Twitter.  My handle is benhnet.

Thanks again to everyone that volunteered, organized and attended.

LINQ : DBA vs Developer

Design Patterns For UX

Updated 3/3/2009: I forgot one of the projects being referenced in the Design Patterns for UX.  I have updated the link so please download the project again and it should work.