Unlimited Possibilities through Code
I have gotten asked quite a few times why my Visual Studio looks different, or has some additional feature than another developers. There is a large community of plugins for Visual Studio (quite a few are free). I just wanted to link to two of the most popular that I send to people.
I was recently tasked with creating a number of samples testing the compliance of both VistaDB and Microsoft SQL Server with Linq to Entity queries. Each sample tested if the provider was able to execute the query without error and then compare both queries to ensure that both providers returned the same results. To ensure valid test results I needed all queries to be executed against a single entity model for both database providers. Entity Framework was designed in a generic manner for this very purpose so my task should be trivial correct? In this article I will explain the complications I ran into during my task.
My original Entity Data Model was generated from a VistaDB Northwind example which I had an identical copy of in my local SQL Express server. The process of generating a new data model will add a new appconfig file to your project if there is not already one present. If there is already an appconfig file present the data model will simply add a new connection string to it. Entity Framework connection strings always includes paths to the three files that make up the data model, the database connection string and provider information. The EF connection string that was auto generated for Northwind.vdb4 looks like this.
<add name="NorthwindEntities" connectionString="metadata=res://*/NorthwindModel.csdl|res://*/NorthwindModel.ssdl
|res://*/NorthwindModel.msl;provider=System.Data.VistaDB;provider connection string='Data Source="C:\Northwind.vdb4"'" providerName="System.Data.EntityClient" />
Things to note about the connection string:
· The path of the CSDL file */NorthwindModel.csdl
· The path of the SSDL file */NorthwindModel.ssdl
· The path of the MSL file */NorthwindModel.msl
· The database connection string Data Source=C:\Northwind.vdb4
· Provider Name System.Data.VistaDB
There are some new operations in .Net 4 Entity Framework, this a quick example of each working with VistaDB 4 and Visual Studio 2010. These changes were mostly made to bring LINQ to Entities inline with the other LINQ providers in .Net. Of the list below I think that Single() was the one that most people were confused about because if you used it you would get weird errors that didn’t make a lot of sense.
For a complete list of LINQ to Entities operators visit the Supported and Unsupported LINQ Methods on MSDN.
The operations I want to demonstrate are the new Contains(), Single(), SingleOrDefault(), and DefaultIfEmpty().
These operations are all new in .Net 4, and yes they work with VistaDB 4. I started with a simple one table database called Feedback. The only table has 3 columns:
I added a few small text entries, including “I like grapes'” to search against with the Contains() operator.
©2010-2012 Jason Short. All Rights Reserved. The opinions expressed herein are my own and do not represent my employer’s views in any way.