All posts by Julie

This RIA Services bug from MIX bits has been fixed but until new bits are released, watch out!

The MIX build of RIA services has a bug that has been fixed since. But you might experience it as I did this morning and go around in circles for a while. This blog post is to help you avoid wasting that time.

I normally create my model is in its own project and hadn’t seen this problem until this morning.

If you add a model into a RIA Services project (e.g., the web project created from the Silverlight Business Application template), you must build the project before you create a new Domain Service Class with the wizard.

If the project wasn’t built in advance, then you will see the model, but not the entities:

dsnoentities

What I did then was Cancel and build the project. But it was too late. The entities would not show up after this when I tried to create a new Domain Service class. The only way to get them to show at this point is to close and reopen Visual Studio.

It’s a bug and has been fixed post-Mix, but until then, remember to build after you add in the model file.

Hopefully you won’t spend as much time as I did trying to understand the problem. Thanks to Jeff Handley and Ron Cain from the RIA Services team who finally identified the problem and confirmed that it’s been eradicated.

Include Method Extension for IObjectSet – What about the mocks?

Eager loading with Entity Framework depends on the special ObjectQuery.Include method. We’ve had that from Day 1 (first version of ef).

Now we use ObjectSets in EF4 which inherit from ObjectQuery (thereby inheriting Include) and also implement IObjectSet.

IObjectSet allows us to break the queries apart from ObjectQuery and ObjectContext so we can write persistent ignorant, testable code.

But IObjectSet doesn’t come with the Include method and you have to create an extension method to continue using it.

This is not new. Lots of people have blogged about it before including myself. Here’s a post I wrote about using Include with IObjectSets: http://thedatafarm.wpengine.com/blog/data-access/agile-entity-framework-4-repository-part-5-iobjectset/

This extension method works great when the IObjectSet is the one for your true EF query, therefore an ObjectSet which inherits from ObjectQuery and can leverage the Include.

But what happens when you are testing a method that contains an eager loaded query with Include and you are using a mock context, not the real EF ObjectContext?

The Include method will get ignored.

For example, you may have a method such as:

 

public List<Customer> GetCustomerWithOrders(int customerId)
{
   return context.Customer.Include(“Orders”)
.Where(c=>c.Id==customerId).ToList(); }

In *real* EF, “context.Customer” is an ObjectSet, but if you are using a mock context, then it’s an IObjectSet with no Include.

All you’ll get back after running through the extension method is the Customer — with no orders. But at least the method won’t crash and burn.

But what if the method does something like this:

public string BuildEmailForCustomerWithOrders(int customerId)
{
   var cust=  context.Customer.Include(“Orders”).FirstOrDefault(c=>c.Id==customerId);
   if (cust.Orders>0)
    return “Dear” + cust.Name + “, Thanks for your order”
   else
    return “Dear” +cust.Name+ “, Screw you for not placing any orders”;
}

You might then have a test to be sure that good customers get a nice email and bad customers get the nasty email.

With the mocks, you can’t test that because Orders will always be 0.

Here’s an easy solution….just create a special mock context that is used anywhere you need to test methods that contain Includes.

And instead of it’s Customers property returning customers, the Customers property should construct a customer with some orders in its Orders property and return that.

Long story to get to a very simple solution – which may be obvious to pro testers – but is not necessarily to us newbies.

I already have a bunch of mocks…good data mocks to test valid validations…bad data mocks to test invalid validations, etc. So creating a mock so that my methods that happen to contain Include queries can still be tested was a no-brainer (once I was confident there was no way (and really, no need) to generically emulate the Include behavior).

Entity Framework POCO Template for .NET 3.5

UPON REFLECTION, I DECIDED THAT THIS POST WAS PRETTY MISGUIDED (must have been one of those days…).

So, for safety , I have removed it completely.

You *can* use T4 to customize the code generated for EntityObjects but if you begin with the T4 EntityObject template and replace .NET 4.0 specific logic with old style. FOr example ObjectSet & CreateObjectSet needs to be replaced by ObjectQuery and CreateQuery.

When I have some time, I will update this post to show how to do it.

VS2010 Gotcha: Inadvertently targeting the wrong framework

I love VS2010’s multi-framework targeting feature, yet it has bitten me in the rear-end more than once.

The problem is that I have created projects in .NET 3.5 without realizing it, then at some point, when something doesn’t work as expected, if I’m lucky I discover the mistake.

Typically, this happens after you have explicitly chosen .NET 3.5 as the target framework. Then every project after that will be .NET 3.5 until you explicitly choose .NET 4.0 again.

This morning that wasn’t the case. I was workign with a brand new installation of VS2010 RC and created a new class library then added to it an entity data model.

All of the features worked as expected except that I couldn’t generate a new code generation item.

Finally when I created a console app and attempted to add a reference to System.Data.Entity, I noticed that I was only seeing 3.0 and 3.5 versions of assemblies in the Add Reference dialog and realized my mistake (of creating the .NET 3.5 project).

This was in the middle of recording a session of DNRTV so turns out to be a really good lesson for viewers.

But I sure wish Visual Studio 2010 would warn me when I am creating a non .NET 4.0 project.

Two more Entity Framework videos on Pluralsight

Two new videos that I have created for Visual Studio 2010 have just been published to Pluralsight On-Demand.

If you don’t have a Pluralsight subscription (yet), these videos are available as part of POD’s free guest pass along with lots of other great content.

The new vids are “Exploring the Classes Generated from an Entity Data Model” and “Consuming an Entity Data Model from a Separate .NET Project”.

EFPSOD

They’ll be available on the MSDN Data Developer center as well (msdn.microsoft.com/data) in the very near future.

March 24 VTSQL Meeting: BI with SQL Server guru Rushabh Mehta

When: March 24th, 6PM

Where: Competitive Computing, Colchester Vermont (www.competitive.com)

From Zero to BI in 10 Minutes or less

By Rushabh Mehta

Finally a technology that the Information Worker can use to take raw data and turn it into valuable information in a matter of minutes from the comfort of their own desktop! In this very exciting and interactive session full of exciting demos, we will walk you through taking raw information from a variety of sources and building a powerful analytical model that can then be used for deep analysis and reporting. We will further see how this set of technologies revolving around the Office 2010 platform and SQL Server 2008 R2 will transform the way information workers will become self-sufficient with their ad-hoc BI and reporting needs.

If you are an information worker, a data junkie, a BI wannabie, want to see some amazing advancements in the Microsoft SQL Server technology stack or just spend an evening and have dinner with us then plan to attend this incredible session.

rushabh_mehta_04  Rushabh Mehta is the President of PASS (The Professional Association for SQL Server), a leading BI expert working with Solid Quality Mentors and also the Managing Director for Solid Quality India P.L. Rushabh has been architecting and implementing large and complex Business Intelligence solutions for organization like Raymond James, Microsoft, US Department of Defense, Jackson Hewitt and many more for over 10 years. He has also developed a number of industry best practices in Business Intelligence arena. Rushabh has also written multiple advanced training courses in Business Intelligence and to date has delivered over 4000 hours of advanced classroom training to over 250 organizations around the world. Rushabh has also mentored a large number of BI professionals around the world, providing them the know-how to successfully build BI solutions for their organizations. Rushabh speaks regularly at large conferences such as PASS, Tech Ed and many others around the world and can frequently be found speaking at some local user group during his travels. Rushabh is also a recipient of the Microsoft Most Valuable Professional (MVP) award in the SQL Server competency consecutively for the past 4 years and was recently a contributing author for a book on SQL Server Integration Services 2008 (Problem-Design-Solution) where he wrote a chapter outlining a solution for building a scale-out ETL process with SSIS based on work he did at Microsoft for building the analytical platform for Windows Azure.

About Solid Quality Mentors

Founded in 2002, Solid Quality Mentors is comprised of over 100 of the leading experts in over 10 active subsidiaries around the world, specializing on Microsoft Data Platform and providing advanced and custom training, mentoring and expert consulting services. Our customers include Microsoft, AT&T, Associated Press, Alcoa Howmet, BBC, Capital One, Career Builder, Concord Group Insurance, Conoco Phillips, Georgia Pacific, Harris Interactive, Jackson Hewitt, Lockheed Martin, Mitsui Sumitomo Insurance, Premier Bankcard, Progressive Insurance, Raymond James, USDA, US Veterans Health Administration, US Department of Defense, Zillow.com and many more. You can find more information at www.solidq.com or contact us at info@solidq.com.