Random Dev Notes

May 6, 2012

Using VFP Entity Framework Provider with Free Tables using Code First

Filed under: .Net Development — Tags: — Tom Brothers @ 3:37 pm

Introduction

In my previous post, titled “Using VFP Entity Framework Provider with Free Tables”, I outlined a way of connecting the VFP Entity Framework Provider with Free Tables.  The post was really geared towards an “out of the box” experience – said another way it was more specifically an Entity Framework 4.0 way.  Although I feel the post is relevant, it really didn’t sit well with me because it is not the way I would have done things.  This post will outline another way of connecting Free Table DBFs with the VFP Entity Framework Provider using Code First (or Entity Framework 4.1+).

(This post assumes you’ve already installed the VFP Entity Framework Provider)

Getting Started

Create a console application.

image

Create the Entities.

  1. Install the Entity Framework Power Tools
    image
  2. Use the Power Tools to generate the code first entities.
    image
  3. You’ll be prompted for the connection information.
    image 
    image
  4. A new Models folder has been added to the project.
    image

Alter the Model

I’ll alter the Blog_Lookups table just list in the last blog post.

Here is the code that was generated:

image

Using Visual Studio’s refactoring I renamed the class name and some of the properties.

image

One other thing that needs to be done which I couldn’t do in the last example is set the primary key to the correct column.

image

 

* One benefit of the using the Code First approach makes it easier to set the primary key when your table doesn’t include a candidate key.

5 Comments »

  1. Perfect job.
    We have jus one problem
    Line feed and carriage return (‘\r\n’) causes ‘Command contains unrecognized phrase/keyword’ error in db.SaveChanges() line
    Is there a solution for this?

    Comment by fikret — June 1, 2012 @ 12:00 pm

    • (hanging my head in shame)

      Major failure… thanks for bringing that to my attention. I posted a new build with a fix for this issue.

      Comment by Tom Brothers — June 3, 2012 @ 11:14 am

      • Excellent. It is working now.

        Comment by fikret — June 4, 2012 @ 2:27 am

  2. Hello, I tried to do this but I got this error message. System.Data.ProviderIncompatibleException: The store provider factory type ‘System.Data.OleDb.OleDbFactory’ does not implement the IServiceProvider interface

    Comment by jack — August 11, 2016 @ 9:08 am

    • I haven’t seen that error before. Could you send me an example project to see if I can help debug the issue? (tombrothers@outlook.com)

      Comment by Tom Brothers — August 15, 2016 @ 5:35 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: