Generating an Entity Data Model in Visual Studio Express



Entity Framework is an ORM (object-relational mapping) framework that can be used to work with data as objects. Visual Studio Express, however, doesn't offer integration for third-party entity framework providers to be used as data sources.

There are two easy solutions: Use the code-first approach to manually define your Entity Data Model or Generate the model using the EDM generator (edmgen) as outlined in this article. Although this article uses the QuickBooks Data Provider as an example, the same process can be used with any CData ADO.NET Data Providers.

  1. In Visual Studio Express, create a Windows Console Application using .NET Framework 4.0.
  2. Add a reference to the System.Data.Entity.dll and System.Runtime.Serialization.dll assemblies.
  3. You can now generate the data model. Open the command prompt, navigate to your project directory, and execute edmgen.exe as shown below. Note you will need to pass the connection string using the '/c:' parameter. Example connection strings are available in the documentation for each provider. You will also need to point to the correct DLL in the '/prov:' parameter. If you are making a Visual Basic project, set the language to 'VB'.

    "%windir%\Microsoft.NET\Framework\v4.0.30319\edmgen.exe" /mode:fullgeneration /prov:"System.Data.CData.QuickBooks" /c:"user=MyUserName;Password=MyPassword;URL=MyURL" /project:QBTest /entitycontainer:QuickBooksEntities /namespace:QBTest /language:CSharp

    To connect to Desktop editions of QuickBooks, use the Remote Connector application installed with the application. The Remote Connector is a lightweight, stand-alone server that enables you to connect to remote QuickBooks instances. It is also used to connect your application to QuickBooks in situations where direct COM access to QuickBooks is not available (e.g., ASP.NET, Java, or a company file on a remote machine). For more information and a step-by-step guide to establish a connection, refer to the "Getting Started" guide in the help documentation.

  4. After the command completes, there should be five new files created in the working directory: QBTest.csdl, QBTest.msl, QBTest.ObjectLayer.cs, QBTest.ssdl, and QBTest.Views.cs. (If you chose VB for the language, you will have .vb files instead of .cs.) Add these files to your project.
  5. In the Properties tab, set the "Copy to Output Directory" property to "Copy if newer" for the .csdl, .msl, and .ssdl files.
  6. You should now be ready to start using your Entity Data Model. For example, the following will perform a simple query on the Accounts table to retrieve the Ids:
  7. string conn = "metadata=./QBTest.csdl|./QBTest.ssdl|./QBTest.msl;provider=System.Data.CData.QuickBooks;provider connection string='User=MyUserName;Password=MyPassword;URL=MyURL;'";
    QuickBooksEntities env = new QuickBooksEntities(conn);
    var queryRet = from account in env.Accounts select account;
    foreach (var results in queryRet) {
      Console.WriteLine(results.ID);
    }
 
 
Downloads